我遇到的问题是即使执行它,tkinter窗口仍然是空白的。作为副作用,窗口不会刷新以更新动作检查按钮。
from tkinter import *
Pieces = {}
Actions =[]
class GameCreation(Frame):
def __init(self,master):
super(GameCreation,self).__init__(master)
self.grid()
self.CreatePiece()
#Creating pieces function
def CreatePiece(self):
Label(self,text ="What piece are we working with?").grid(row =0,
column = 0,
sticky = W)
self.piece_entry = Entry(self)
self.piece_entry.grid(row =0,
column = 1,
sticky = W)
Label (self, text = "Tick all the actions which the piece has").grid (row =1,
column = 0,
sticky = W)
self.Actions = BooleanVar()
self.Actions.set(None)
column = 0
row = 4
for action in Actions:
Checkbutton(self,text = action, variable = self.checkButton, value = action).grid( row = row,
column = column,
sticky = W)
if column == 5:
row +=1
column = 0
else:
column +=1
Button(self,text = "Add action", command = self.AddAction).grid(row = 1,
column = 0,
sticky = W)
self.action_entry = Entry(self)
self.action_entry.grid(row = 1, column = 1, sticky = W)
Button (self, text = "Create piece and it's actions", command = Add_to_dict).grid(row =2,
column = 0,
sticky = W)
self.Add_dict = Text(self, width =10, height = 2, wrap = WORD)
self.Add_dict.grid( row = 3, column = 0, columnspan = 4)
此功能应添加到动作列表
def addAction(self):
action = self.action_entry.get()
Actions.append(action)
此功能应该只打印作品的名称和为其选择的动作
def Add_to_dict(self):
actions = Actions.get()
piece = piece_entry.get()
rules = piece, ":", actions
self.Add_dict.delete(0.0,END)
self.Add_dict.insert(0.0,rules)
答案 0 :(得分:2)
您需要使用__init__
,而不是__init
此外,如果您正在使用BooleanVar
,则必须将其设置为True
或False
,而不是None
:
self.Actions.set(False)
此外,您有一个名为addAction
的方法,但您将其称为self.AddAction
,并且您有一个名为Add_to_dict
的方法,您调用Add_to_dict
而非self.Add_to_dict
。
最后,您似乎无法在任何地方创建GameCreation实例。