from tkinter import *
import tkinter as tk
Creating a counter
def a():
def counter_label(label):
counter=
In function a()
you never actually call the counter_label
, so it doesn't start the count. And you need to define counter
variable outside of the function so that you can use global
keyword.
Here is your code modified:
from tkinter import *
import tkinter as tk
counter = 0 #Defining counter so you can use it with global
def a():
def counter_label(label):
counter=0
def count():
global counter
counter += 1
label.config(text=str(counter))
label.after(1000,count)
count()
label=tk.Label(frame,fg="red")
label.grid(row=0,column=1)
counter_label(label) #Calling the counter_label function
...