#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()
每当我在IDLE中运行时,tkinter窗口都没有出现,当我将它运行到命令行(python one ...)时,它会显示窗口,但没有&#34;提交&#34;按钮。
我真的很困惑请帮忙!
答案 0 :(得分:0)
首先,您是否意识到您的GUI程序要求从命令行输入,并且在创建提交按钮之前您正在执行?这就是为什么提交按钮没有显示的原因。如果您正在编写GUI程序,则不应尝试从命令行读取输入。
如果从终端输入10到50之间的数字,则代码应显示一个窗口。但是,如果输入该范围之外的数字,由于while no_counters ...
循环,将不会显示任何内容。该循环将无限运行,阻止与GUI的任何其他交互,并阻止任何其他小部件显示。