我是初学程序员。我想调整我的按钮的大小,按钮定义为"但是",并且它在Square类中定义。我会用什么选项来调整此按钮的大小来调整高度和宽度?非常感谢任何帮助,如果您可以在代码中添加注释,那将会很有帮助!
import Tkinter
class TicWindow(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.squares = []
self.turn = 0
for r in range(3):
for c in range(3):
b = Square(self).grid(row=r,column=c)
self.squares.append(b)
self.geometry("500x500")
def turn(self):
return self.turn
def changeTurn(self):
if (self.turn == 0):
self.turn = 1
else:
self.turn = 0
class Square(Tkinter.Button):
def __init__(self,parent):
but = Tkinter.Button.__init__(self,parent, text=" ", command=self.changeButtonText)
self.canClick = True
def changeButtonText(self):
if (self.master.turn == 0) and (self.canClick == True):
self.config(text = "X")
elif (self.master.turn == 1) and (self.canClick == True):
self.config(text = "O")
self.master.changeTurn()
self.hasBeenClicked()
def canClick(self):
return self.canClick
def hasBeenClicked(self):
self.canClick = False
class ScoreBoard(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.board = Tkinter.Label(self, text = "No Score Yet")
self.board.pack()
self.geometry("500x500+300+300")
top = TicWindow()
scoreboard = ScoreBoard()
top.mainloop()
答案 0 :(得分:4)
这有一个简单的答案。 基本上,只需在创建按钮时添加高度和宽度变量:
Tkinter.Button.__init__(self,parent, text=" ", command=self.changeButtonText, height = 20, width = 30)
您可以修改高度和宽度按钮以更改按钮的大小。