为什么不显示我的按钮??

2024-10-02 10:18:38 发布

您现在位置:Python中文网/ 问答频道 /正文

#Last one Looses (II)
from tkinter import *
from tkinter import ttk
root = Tk()

#window
root.title("Last one Looses Mark II")

#Counters Entry
counters = StringVar()
countersL = Label(root, text = "How many counters do you want to play with (10-50)")
countersL.pack(side = LEFT)
countersE = Entry(root, textvariable = counters, bd = 5)
countersE.pack(side = RIGHT)
#Function to process this
def countersinput():
    no_counters = int(input(counters.get()))
no_counters = int(input(counters.get()))
#Submit Button
countersB = Button(root, text = "Submit", command = countersinput)
countersB.pack(side = BOTTOM)
#Making sure the counters are between 10-50
while no_counters > 50 or no_counters < 10:
    Error = Message(root, text="You need to pick between 10 and 50 counters...")
    Error.pack()
    counters = StringVar()
    countersL = Label(root, text = "How many counters do you want to play with (10-50)")
    countersL.pack(side = LEFT)
    countersE = Entry(root, textvariable = counters, bd = 5)
    countersE.pack(side = RIGHT)
    def countersinput():
        no_counters = int(input(counters.get()))
    countersB = Button(root, text = "Submit", command = countersinput)
    countersB.pack(side = BOTTOM)

#Sucess Message
Sucess = Message(root, text=("You are playing with",no_counters,"counters"))

root.mainloop()

每当我在空闲状态下运行它时,tkinter窗口不会出现,当我在命令行(python one…)中运行它时,它会显示窗口,但没有“submit”按钮

我真的很困惑请帮帮我


Tags: tonotexttkinterwithrootoneside
1条回答
网友
1楼 · 发布于 2024-10-02 10:18:38

首先,您是否意识到您的GUI程序正在请求来自命令行的输入,并且您在创建submit按钮之前正在这样做?这就是为什么提交按钮没有出现的原因。如果您正在编写GUI程序,则不应尝试从命令行读取输入

如果从终端输入10到50之间的数字,代码将显示一个窗口。但是,如果输入的数字超出该范围,则由于while no_counters ...循环,将不会显示任何内容。该循环将无限地运行,防止与GUI的任何其他交互,并防止任何其他小部件出现

相关问题 更多 >

    热门问题