I have 2 codes I made. The 2nd one is based off of the first one. Unfortunately for some reason the 2nd one doesn't work even though the first one does.
First code:
import time
from Tkinter import *
root = Tk()
t=StringVar()
num=1
t.set(str(num)
thelabel = Label(root, textvariable=t).pack()
def printnum (x):
while x<= 100:
t.set(str(x))
x += 1
root.update()
time.sleep(30)
printnum(num)
root.mainloop()
#!/usr/bin/python
# -*- coding: latin-1 -*-
import Adafruit_DHT as dht
import time
from Tkinter import *
root = Tk()
k=StringVar()
num = 1
k.set(str(num))
thelabel = Label(root, textvariable=k).pack
def printnum(x):
while x <= 10000000000000:
h,t = dht.read_retry(dht.DHT22, 4)
newtext = "Temp%s*C Humidity=%s" %(t,h)
k.set(newtext)
x += 1
root.update
time.sleep(30)
printnum(num)
root.mainloop()
root.update
doesn't do anything. You need to add ()
:
root.update()
That being said, your algorithm is the wrong way to run periodic tasks in tkinter. See http://stackoverflow.com/a/37681471/7432