Anonymous
Вопрос: _tkinter.TclError: невозможно вызвать команду «label»: приложение уничтожено
Сообщение
Anonymous » 28 апр 2024, 00:44
Я сделал игру, в которой нужно угадывать числа. После неоднократных попыток мне так и не удалось изменить проблему.
Код следующий:
Код: Выделить всё
#
#
import tkinter
import random
import pygame
#
pygame.init()
#
root = tkinter.Tk()
#
bg = tkinter.Canvas(root, width=1000, height=750)
bg.pack()
bg_p = tkinter.PhotoImage(file="bg.png")
bg.create_image(500, 375, image=bg_p)
#
bgm = pygame.mixer.Sound("bgm.mp3")
bgm.play(-1)
#
low = 0
high = 101
#
random.randrange(low, high)
#
def onclick():
#
global low, high
#
guess = int(input("Guess a number: "))
#
if guess == answer:
#
bg = tkinter.Canvas(root, width=1000, height=750)
bg.pack()
bg_p = tkinter.PhotoImage(file="bingo.png")
bg.create_image(500, 375, image=bg_p)
#
low = guess
high = guess
#
bingo = pygame.mixer.Sound("bingo.mp3")
bingo.play(0)
#
elif guess > answer:
#
bg = tkinter.Canvas(root, width=1000, height=750)
bg.pack()
bg_p = tkinter.PhotoImage(file="too_high.png")
bg.create_image(500, 375, image=bg_p)
#
high = guess
#
lol = pygame.mixer.Sound("lol.mp3")
lol.play(0)
#
else:
#
bg = tkinter.Canvas(root, width=1000, height=750)
bg.pack()
bg_p = tkinter.PhotoImage(file="too_low.png")
bg.create_image(500, 375, image=bg_p)
#
low = guess
#
lol = pygame.mixer.Sound("lol.mp3")
lol.play(0)
#
while True:
#
for event in pygame.event.get():
#
if event.type == pygame.QUIT:
#
pygame.quit()
exit()
#
if event.type == pygame.MOUSEBUTTONDOWN:
#
onclick()
#
try:
#
l1.destroy()
l2.destroy()
#
except:
#
pass
#
finally:
#
l1 = tkinter.Label(root, text=str(low), font=("Arial", 60), bg="white")
l1.place(x=280, y=570)
l2 = tkinter.Label(root, text=str(high), font=("Arial", 60), bg="white")
l2.place(x=630, y=570)
#
root.mainloop()
После выполнения программы возвращается
_tkinter.TclError: невозможно вызвать команду «label»: приложение уничтожено .
Независимо от того, где Я включил mainloop(), он не работает.
Почему?
Я везде включил mainloop(), но он все равно не работает.
Подробнее здесь:
https://stackoverflow.com/questions/783 ... n-has-been
1714254295
Anonymous
Я сделал игру, в которой нужно угадывать числа. После неоднократных попыток мне так и не удалось изменить проблему. Код следующий: [code]# # import tkinter import random import pygame # pygame.init() # root = tkinter.Tk() # bg = tkinter.Canvas(root, width=1000, height=750) bg.pack() bg_p = tkinter.PhotoImage(file="bg.png") bg.create_image(500, 375, image=bg_p) # bgm = pygame.mixer.Sound("bgm.mp3") bgm.play(-1) # low = 0 high = 101 # random.randrange(low, high) # def onclick(): # global low, high # guess = int(input("Guess a number: ")) # if guess == answer: # bg = tkinter.Canvas(root, width=1000, height=750) bg.pack() bg_p = tkinter.PhotoImage(file="bingo.png") bg.create_image(500, 375, image=bg_p) # low = guess high = guess # bingo = pygame.mixer.Sound("bingo.mp3") bingo.play(0) # elif guess > answer: # bg = tkinter.Canvas(root, width=1000, height=750) bg.pack() bg_p = tkinter.PhotoImage(file="too_high.png") bg.create_image(500, 375, image=bg_p) # high = guess # lol = pygame.mixer.Sound("lol.mp3") lol.play(0) # else: # bg = tkinter.Canvas(root, width=1000, height=750) bg.pack() bg_p = tkinter.PhotoImage(file="too_low.png") bg.create_image(500, 375, image=bg_p) # low = guess # lol = pygame.mixer.Sound("lol.mp3") lol.play(0) # while True: # for event in pygame.event.get(): # if event.type == pygame.QUIT: # pygame.quit() exit() # if event.type == pygame.MOUSEBUTTONDOWN: # onclick() # try: # l1.destroy() l2.destroy() # except: # pass # finally: # l1 = tkinter.Label(root, text=str(low), font=("Arial", 60), bg="white") l1.place(x=280, y=570) l2 = tkinter.Label(root, text=str(high), font=("Arial", 60), bg="white") l2.place(x=630, y=570) # root.mainloop() [/code] После выполнения программы возвращается [b]_tkinter.TclError: невозможно вызвать команду «label»: приложение уничтожено[/b]. Независимо от того, где Я включил mainloop(), он не работает. Почему? Я везде включил mainloop(), но он все равно не работает. Подробнее здесь: [url]https://stackoverflow.com/questions/78394981/question-tkinter-tclerror-cant-invoke-label-command-application-has-been[/url]