Threading and tkinter

gert gert.cuykens at gmail.com
Wed Feb 18 21:06:03 EST 2009


Can you first explain why x stay's 0 please and how i should update x
using threads ?

from tkinter import *
from _thread import start_new_thread
from time import sleep

x=0
def weegbrug(x):
    while True:
        x=x+1
        sleep(0.5)
start_new_thread(weegbrug,(x,))

root = Tk()
v = StringVar()
v.set("00000")
txt = Label(root, textvariable=v, width=800, height=600, bg="yellow",
font=("Helvetica", 300))
txt.pack(expand=YES, fill=BOTH)
root.title("Weegbrug")
root.after(500, lambda:v.set(x))
root.mainloop()





More information about the Python-list mailing list