使用时出现错误
def set_size(self, x="500", y="500"):
self.win.geometry("%sx%s+0+0" %(x, y))
_tkinter.TclError:错误的几何说明符“ x + 0 + 0”
和
def set_size(self, x="500", y="500"):
self.win.geometry("500x500+0+0")
还可以
这是所有代码
class Game():
win = Tk()
max_x = win.winfo_screenwidth()
max_y = win.winfo_screenwidth()
def __init__(self):
self.win.title("Game Of Life")
self.win.geometry("300x300+0+0")
def set_size(self, x="500", y="500"):
self.win.geometry("%sx%s+0+0" %(x, y))
def init_size(self):
f_set_size = Frame(self.win)
f_set_size.pack()
Label(f_set_size, text = "set width").pack()
e_get_x = Entry(f_set_size)
e_get_x.pack()
Label(f_set_size, text = "set height").pack()
e_get_y = Entry(f_set_size)
e_get_y.pack()
b_set_xy = Button(f_set_size, text = "set size", command = self.set_size(e_get_x.get(), e_get_y.get()))
b_set_xy.pack()
def mainloop(self):
self.win.mainloop()
if __name__ == "__main__":
g = Game()
g.init_size()
g.mainloop()
为什么%s似乎不起作用 ........................... 并且...总是pack()非常麻烦。 方便吗?