使用 tkinter 創建一個需要一些縱橫比才能正常作業的應用程式,為此我需要保持主視窗的比例,但是如果我系結一個所以當視窗重繪 時它會進入無限回圈,任何檢查這個的方法只有當有人在應用程式中調整大小時才真正這樣做?
def appBinds(self):
def keepRatio(e):
width = int(e.width)
height = int(width/0.75)
self.geometry(f'{width}x{height}')
self.unbind('<Configure>')
print(e)
self.bind('<Configure>', keepRatio)
uj5u.com熱心網友回復:
為避免無限回圈問題,您self.geometry(...)只需要在高度不是預期高度時呼叫,如下所示:
def appBinds(self):
def keepRatio(e):
if e.widget is self:
height = int(e.width / 0.75)
if e.height != height:
self.geometry(f"{e.width}x{height}")
self.bind('<Configure>', keepRatio)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/510577.html
標籤:tkinterttk
