有没有办法使用appJar本身来获得屏幕的高度和宽度。
由于appJar是tkinter的包装器,所以有一种方法可以创建一个Tk()实例来使用我在研究期间见过的以下代码:
import tkinter
root = tkinter.Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()我希望这样做,这样我就可以使用这些大小来稍后使用.setGeometry()方法设置窗口大小。
# Fullscreen
app.setGeometry(width, height)或者:
# Horizontal halfscreen
app.setGeometry(int(width / 2), height)或者:
# Vertical halfscren
app.setGeometry(width, int(height / 2))发布于 2017-09-25 14:39:56
因为appJar只是tkinter上的一个包装器,所以您需要引用Tk()的root/master实例,该实例在gui中存储为self.topLevel。或者,您可以引用一个更漂亮的self.appWindow,它是self.topLevel的“子”画布。
为了使所有事情都清楚,只需添加一些“快捷键”到想要的方法的继承类!
import appJar as aJ
class App(aJ.gui):
def __init__(self, *args, **kwargs):
aJ.gui.__init__(self, *args, **kwargs)
def winfo_screenheight(self):
# shortcut to height
# alternatively return self.topLevel.winfo_screenheight() since topLevel is Tk (root) instance!
return self.appWindow.winfo_screenheight()
def winfo_screenwidth(self):
# shortcut to width
# alternatively return self.topLevel.winfo_screenwidth() since topLevel is Tk (root) instance!
return self.appWindow.winfo_screenwidth()
app = App('winfo')
height, width = app.winfo_screenheight(), app.winfo_screenwidth()
app.setGeometry(int(width / 2), int(height / 2))
app.addLabel('winfo_height', 'height: %d' % height, 0, 0)
app.addLabel('winfo_width', 'width: %d' % width, 1, 0)
app.go()发布于 2017-09-25 13:28:46
幸运的是,appJar允许您创建Tk()实例。因此,我能够创建一个实例,使用这些函数检索维度并销毁当时不需要的实例。
# import appjar
from appJar import appjar
# Create an app instance to get the screen dimensions
root = appjar.Tk()
# Save the screen dimensions
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
# Destroy the app instance after retrieving the screen dimensions
root.destroy()https://stackoverflow.com/questions/46405870
复制相似问题