моя привязка не будет выполнять мою функцию я tkinter - PullRequest
0 голосов
/ 30 октября 2019

так что я делаю простую текстовую игру, и когда я пытаюсь прикрепить игру () к функции, она не запускает игру (), и никаких ошибок не появляется, спасибо

def game():
    root.counter += 1
    global cel_txt1
    global play_txt1
    if str(root.counter) == "1":
        cel_txt1 = Label(root, image=cel_bilde1)
        cel_txt1.pack()
    if str(root.counter) == "2":
        play_txt1 = Label(root, image=play_bilde1)
        play_txt1.pack()
        cel_txt1.pack_forget()
    if str(root.counter) == "3":
        cel_txt2 = Label(root, image=cel_bil2)
        cel_txt2.pack()
        play_txt1.pack_forget()

root.after(1, game)
c.bind("<Button-1>", game)

1 Ответ

0 голосов
/ 30 октября 2019

Я понял это, я только что написал глобальный cel_txt1 и все было исправлено. (кстати, c был холстом, который я сделал, чтобы связать)

вот новый и улучшенный кусок кода;

`def game():
    root.counter += 1
    global cel_txt1
    global play_txt1
    global cel_txt2
    global cel_txt3
    if str(root.counter) == "1":
        cel_txt1 = Label(root, image=cel_bilde1)
        cel_txt1.pack()
    if str(root.counter) == "2":
        play_txt1 = Label(root, image=play_bilde1)
        play_txt1.pack()
        cel_txt1.pack_forget()
    if str(root.counter) == "3":
        cel_txt2 = Label(root, image=cel_bil2)
        cel_txt2.pack()
        play_txt1.pack_forget()
    if str(root.counter) == "4":
        cel_txt3 = Label(root, image=cel_bil3)
        cel_txt3.pack()
        cel_txt2.pack_forget()
    if str(root.counter) == "5":
        name = Label(root, image=navn)
        name.pack()
        cel_txt3.pack_forget()
        e = Entry(root)`
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...