我的问题是,如果我启动它,计数器不可见,如果我关闭程序,它会给我以下错误:
File "C:\Users\****\AppData\Local\Programs\Python\Python36-32
\lib\tkinter\__init__.py", line 1176, in update_idletasks
self.tk.call('update', 'idletasks')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
这是我的代码:
from tkinter import *
import tkinter.messagebox
fenster = Tk()
tkinter.messagebox.showinfo("", "Willkommen bei wer wird Millionär")#Welcome to who is Millionaire
answer = tkinter.messagebox.askquestion("", "Möchtest du im Schweren Modus spielen? Der schwere modus bedeutet das du nur 2 Joker hast!")#Do you want to play in Hard mode?if you play in hardmode you only have 2 joker
menu = Menu(fenster)
fenster.config(menu=menu)#window
frage = Label()#question
frage.grid(row=0, column=1)
ausgabe = Label()#output
ausgabe.grid(row=4, column=1)#output
jokerfrage = None
zähler = Label(fg="black")
zähler.grid(row=0, column=0)
x = 0
v = IntVar()
def fiftyfifty():
subMenu.delete("50/50", index2=None)#Fiftiy fifty Joker
def fiftyfifty1():
subMenu.delete("1.50/50", index2=None)#Fiftiy fifty Joker
def fiftyfifty2():
subMenu.delete("2.50/50", index2=None)#Fiftiy fifty Joker
def publikum():
print("Publikum ist nicht anwesend tut mir leid!")#Sorry there is no people that can help you
def jokerfragen():
global jokerfrage
jokerfrage = tkinter.messagebox.askquestion("", "Hör auf nachzudenken und benutz lieber einen Joker!")#Stop thinking use a joker!
def antwortr():
frage.configure(text="Glückwunsch deine antwort war richtig")#Greetings youre answers whas right
ausgabe.configure(text="50")
zähler.after(29000, jokerfragen)#which joker he wants
def antwortf():
frage.configure(text="Deine antwort wahr falsch damit bist du ausgeschieden!")#Sorry youre answer whas wrong you lost the game
def vändern1():
v = 1
if v == 1:
knopf1 = Button(text="Einlocken", command=antwortr)#Lock in
knopf1.grid(row=3, column=1)
def vändern2():
v = 2
if v == 2:
knopf1 = Button(text="Einlocken",command=antwortf)#Lock in
knopf1.grid(row=3, column=1)
if answer == "no":
subMenu = Menu(menu)
menu.add_cascade(label="Joker", menu=subMenu)
subMenu.add_command(label="1.50/50", command=fiftyfifty1)#2 wrong question go away
subMenu.add_command(label="2.50/50", command=fiftyfifty2)#2 wrong question go away
subMenu.add_separator()
subMenu.add_command(label="1.Publikum Befragen", command=publikum)#ask other people joker
subMenu.add_command(label="2.Publikum Befragen", command=publikum)#ask other people joker
x = x + 1
if answer == "yes":
subMenu = Menu(menu)
menu.add_cascade(label="Joker", menu=subMenu)
subMenu.add_command(label="50/50", command=fiftyfifty)
subMenu.add_separator()
subMenu.add_command(label="Publikum Befragen", command=publikum)#ask other people joker
x = x + 1
# Frage 1
if x == 1:
frage.configure(text="Wie heist das heilige Buch der Christen?")#What is the Holy book of the Christians
Radiobutton(fenster, text="Bibel", variable=v, value=1, command=vändern1).grid(row=1, column=0)
Radiobutton(fenster, text="Thora", variable=v, value=2, command=vändern2).grid(row=1, column=1)
Radiobutton(fenster, text="Koran", variable=v, value=3, command=vändern2).grid(row=2, column=0)
Radiobutton(fenster, text="Tipitaka", variable=v, value=4, command=vändern2).grid(row=2, column=1)
def counter_label():
while True: # keeps looping forever
for counter in range(30, -1, -1): # loops backwards from 30 up to and including 0
zähler.config(text = str(counter))
zähler.after(1000, count)
sleep(1000)
while jokerfrage is None:
fenster.mainloop(10)
fenster.update()
fenster.update_idletasks()
if jokerfrage == "yes":
wjokerfrage = tkinter.messagebox.askquestion("", "50/50 ist Ja Publikum Befragen ist nein")#which Joker you want 50/50 is yes ask other people joker is no
if jokerfrage == "no":
tkinter.messagebox.showinfo("", "Ok ich werde dir weitere 30 sekunden zum nackdenken geben")#ok I'll give you 30 more seconds to think
mainloop()
这就是我的整个程序,我是 Python 新手,这是我在学校的第一个“更大”项目,但我有很多问题,没有你们我无法纠正。
给你。这是您的程序的工作代码。正如我在之前的评论中所说的问题是,您一开始就从未调用过您的函数。所以你实际上从未拥有过
counter_label()
。
def counter_label(count):
label['text'] = count
if count > 0:
fenster.after(1000, counter_label, count-1)
else:
dostuff()
label = Label(fenster)
label.grid()
counter_label(30)
def dostuff():
print("hi")