使用这些“ while循环”时,为什么我的窗口没有显示在python中?

时间:2018-10-12 04:19:38

标签: python loops tkinter

在运行这段代码时请提供帮助,没有任何显示? 但是在没有循环运行之前,它工作得很好。 在“错误”部分中,它仅表示“ ======重新启动:C:/ Users / --- / OneDrive / Desktop / Tkinter程序test.py ======”

from tkinter import *
from random import randint


def pressbutton_1_10():
    randomnumber.delete(0.0, END)
    randomnumber.insert(END, str(randint(1, 10)))


def pressbutton_1_100():
    randomnumber.delete(0.0, END)
    randomnumber.insert(END, str(randint(1, 100)))

def pressed_the_button_a():
    pressbutton_1_10()
    button1.forget()
    have_not_pressed_buttons == False

def pressed_the_button_b():
    pressbutton_1_100()
    button2.forget()
    have_not_pressed_buttons = False


again = True
while again == True:
    background = Tk()
    have_not_pressed_buttons = True
    randomnumber = Text(background, width=100, height=10)
    randomnumber.pack()
    while have_not_pressed_buttons == True:
        button1 = Button(background, text='Press for a random number between 1 and 10', command=pressed_the_button_a)
        button1.pack()
        button2 = Button(background, text='Press for a random number between 1 and 100', command=pressed_the_button_b)

        button2.pack()
    restart = Button(background, text='Press to get the buttons back', command = again == True)
    stop = Button(background, test = 'Press to end the program', command = again == False)
    restart.pack()
    stop.pack()
    background.bind_all('<Button-1>', pressed_the_button_a)
    background.bind_all('<Button-1>', pressed_the_button_b)

0 个答案:

没有答案