【发布时间】:2017-12-16 03:08:35
【问题描述】:
我想知道如何更改按钮的坐标和大小。我知道您可以使用button1.pack(side=RIGHT),但如果我想说button1.pack(x=100, y=40)。我试过button1.geometry,但没用。
回答:
我做了button1.place(x=0, y=0),按钮转到了顶角。
如果有人好奇,这是我使用的代码:
from tkinter import *
t = Tk()
t.title("Testing")
t.geometry("250x250")
MyButton = Button(t, text="Click Me")
MyButton.pack()
def Clicked(event):
MyButton.place(x=0, y=0)
MyButton.bind("<Button-1>" ,Clicked)
MyButton.pack()
t.mainloop()
【问题讨论】:
-
您只能将
x,y与布局管理器place()一起使用,但您不应该使用其他布局管理器 -pack()、grid()。