我的目标是使GUI根据画布的大小而变化。我需要能够主动检查窗口大小,以便我知道何时显示额外的。使用Python3.8.2 GuiZero
发布于 2020-03-26 09:01:14
您可以在画布上使用tkinter event <Configure>:
def on_resize(event):
print(app.height)
...
app.tk.bind('<Configure>', on_resize)发布于 2020-03-26 04:58:35
我终于可以做一些东西了,但在应用程序退出后,它确实抛出了错误。
w=None
while True:
x=app.tk.winfo_height()
if x!=w:
print(x)
w=app.tk.winfo_height()
app.update()发布于 2020-06-15 22:29:34
我在使用树莓派和两个电位器作为水平和垂直控制创建数字蚀刻草图时遇到了这个问题。如何获取当前画布的大小?令人恼火的是,当您将高度和宽度设置为"fill",然后尝试询问这些值时,得到的结果都是"fill“,如果您试图确定可用画布的上限,这是没有用的。我深入研究了对象层次结构,发现.tk_winfo_height()和.tk.winfo_width()返回整数值。为此,我删除了对电位器旋转做出反应的代码,并在屏幕底部放置了一排按钮来控制垂直和水平移动。
from guizero import App, Box, Drawing, PushButton
x = 0
y = 0
def clear_screen():
drawing.clear()
def move_left():
global x, y
if x > 0 :
drawing.line(x, y, x - 1, y)
x = x - 1
def move_right():
global x, y
if x < drawing.tk.winfo_width() :
drawing.line(x, y, x + 1, y)
x = x + 1
def move_up():
global x, y
if y > 0 :
drawing.line(x, y, x, y - 1)
y = y - 1
def move_down():
global x, y
if y < drawing.tk.winfo_height() :
drawing.line(x, y, x, y + 1)
y = y + 1
app = App()
drawing = Drawing(app, height="fill", width="fill")
drawing.bg="white"
bbox = Box(app, align="bottom")
lbtn = PushButton(bbox, align="left", command=move_left, text="Left")
ubtn = PushButton(bbox, align="left", command=move_up, text="Up")
cbtn = PushButton(bbox, align="left", command=clear_screen, text="Clear")
rbtn = PushButton(bbox, align="left", command=move_right, text="Right")
dbtn = PushButton(bbox, align="left", command=move_down, text="Down")
app.display()https://stackoverflow.com/questions/60855137
复制相似问题