为什么value_sides没有任何价值?我打算在entry_side中写入数字并将值传递给value_sides。
不要介意小部件的顺序,也会删除一些代码,以免混淆视图。
class WindowFunctions:
def __init__(self, root):
self.root = root
self.dice = Die()
self.data = Entry(root)
def taking(self):
value_sides = WindowFunctions(self.root).entry_side.get() # Here is the problem
value_throw = 1000
value_dies = 2
self.dice.generate_sides (value_sides)
result = self.dice.generate_results (value_throw, value_dies)
frequencies = self.dice.generate_frequencies (result)
def window(self):
# ----Entry--------------------------
entry_side = Entry (self.root)
entry_side.pack()
entry_throw = Entry (self.root)
entry_throw.pack()
entry_dice = Entry (self.root)
entry_dice.pack()
# ---Button-----------------------------------------
button_generate = Button(self.root, text='Generate', command=WindowFunctions(self.root).taking)
button_generate.pack()
编辑:这是带根
的文件root = Tk()
root.bind('<Escape>', quit)
die_function = WindowFunctions(root)
die_function.window()
root.mainloop()