Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 文本不';t出现tkintergui_Python_Python 3.x_User Interface_Tkinter - Fatal编程技术网

Python 文本不';t出现tkintergui

Python 文本不';t出现tkintergui,python,python-3.x,user-interface,tkinter,Python,Python 3.x,User Interface,Tkinter,这是我的代码: from tkinter import * import time count = 0 while count >= 0 : print(count) time.sleep(1) count = count + 1 root= Tk() label1= Label(root, text='Gegevens', bg='lightblue') label2= Label(root, text='Voortgang') labelfiets_p

这是我的代码:

from tkinter import *
import time

count = 0
while count >= 0 :
    print(count)
    time.sleep(1)
    count = count + 1


root= Tk()


label1= Label(root, text='Gegevens', bg='lightblue')
label2= Label(root, text='Voortgang')
labelfiets_prestatie= Label (root, text='Fiets_Prestatie',)
labelStappen= Label(root, text='Meter', command= count, bg='red')


label1.pack(fill= X)
label2.pack()
labelfiets_prestatie.pack()
labelStappen.pack()


root.mainloop()

现在我的问题是,每当我删除计数代码时,GUI就会出现,但我希望生成的数字能在GUI中看到。哪里出错了?

我认为你应该在
之后使用
方法

此方法注册一个回调函数,该函数将在 给定的毫秒数。Tkinter保证回调 将不会在此之前调用

您可以签出。如果您想更新标签,可以使用
update\u idletasks

from tkinter import *
from time import sleep
root = Tk()
var = StringVar()   
l = Label(root, textvariable = var)
l.pack()

count=10
while count>=0:
    sleep(1)
    var.set(count)
    count=count-1
    root.update_idletasks()

希望这有帮助。

不要将
.sleep()
tkinter
一起使用。还有一个示例说明如何使用它在文档中创建一个简单的计时器。
from tkinter import *
from time import sleep
root = Tk()
var = StringVar()   
l = Label(root, textvariable = var)
l.pack()

count=10
while count>=0:
    sleep(1)
    var.set(count)
    count=count-1
    root.update_idletasks()