如何使用appJar获取屏幕宽度和高度?

时间:2017-09-25 12:58:42

标签: python-3.x tkinter screen-size

有没有办法使用appJar本身来获取屏幕高度和宽度。

Alternativley,因为appJartkinter的包装器,我有办法创建一个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))

2 个答案:

答案 0 :(得分:1)

由于appJar只是tkinter的包装,因此您需要root / master Tk()实例的引用,其存储为{{1}在self.topLevel中。 或者,您可以参考更漂亮的gui,这是self.appWindow的“子”画布。

要明确所有事情 - 只需在继承类的所需方法中添加一些“快捷方式”!

self.topLevel

答案 1 :(得分:0)

幸运的是,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()