以 4k (3840*2160) 分辨率缩放 Tkinter GUI? [英] Scaling of Tkinter GUI in 4k (3840*2160) resolution?

查看:136
本文介绍了以 4k (3840*2160) 分辨率缩放 Tkinter GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VirtualBox中使用LinuxMint 17.3 Cinnamon,本机使用1920*1080分辨率,开启Hi-DPI选项.主机为Windows 10,分辨率为3840*2160.
尽管在 LinuxMint 中打开了 Hi-DPI 选项,一些应用程序在缩放方面看起来很适合舒适的工作,但是 python-tk GUI (python2) 没有改变 - 字体大小很小,改变了 Cinnamon 中的字体选项不会更改 tk 中的字体.有没有办法正确扩展已经编写的 tk GUI 应用程序?

I use LinuxMint 17.3 Cinnamon in VirtualBox, 1920*1080 resolution is used in this machine, the Hi-DPI option is turned on. The host machine is Windows 10, with 3840*2160 resolution.
Despite turning on Hi-DPI option in LinuxMint, some applications become to look good for comfortable work, in terms of scaling, but python-tk GUI (python2) hasn't been changed - font size is tiny, changing of Font options in Cinnamon doesn't change fonts in tk. Is there any way to scale correctly already written tk GUI applications?

推荐答案

tkinter 有一个内部缩放因子,用于将点和英寸等测量值转换为像素.您可以使用tk scaling"命令进行设置.此命令采用一个参数,即一个点"中的像素数.一个点是 1/72 英寸,因此 1.0 的缩放因子适用于 72DPI 显示器.

tkinter has an internal scaling factor that it uses to convert measurements such as points and inches into pixels. You can set this with the "tk scaling" command. This command takes one argument, which is the number of pixels in one "point". A point is 1/72 of an inch, so a scaling factor of 1.0 is appropriate for a 72DPI display.

root = Tk()
root.tk.call('tk', 'scaling', 2.0)

根据类似问题中的评论,这不会影响默认字体,因为它们是在tkinter 的上下文.如果您以磅为单位指定自己的字体,则它们应遵循此设置.

According to a comment in a similar question, this won't affect the default fonts since they are defined outside the context of tkinter. If you specify your own fonts in points, they should honor this setting.

官方文档缩放 命令是这样的:

The official documentation for the scaling command is this:

设置和查询当前Tk使用的比例因子进行转换物理单位之间(例如,点、英寸或毫米)和像素.number 参数是一个浮点数指定窗口显示上每点的像素数.如果window 参数被省略,它默认为主窗口.如果number 参数被省略,比例因子的当前值是回.

Sets and queries the current scaling factor used by Tk to convert between physical units (for example, points, inches, or millimeters) and pixels. The number argument is a floating point number that specifies the number of pixels per point on window's display. If the window argument is omitted, it defaults to the main window. If the number argument is omitted, the current value of the scaling factor is returned.

点"是等于 1/72 英寸的测量单位.一种缩放因子 1.0 对应于每点 1 个像素,即相当于标准的 72 dpi 显示器.比例因子为 1.25将意味着每点 1.25 像素,这是 90 dpi 的设置监视器;在 72 dpi 显示器上将缩放因子设置为 1.25 会导致应用程序中的所有内容显示为 1.25 倍大如正常.缩放因子的初始值在以下情况下设置应用程序根据已安装监视器的属性启动,但它可以随时更改.缩放后进行的测量因子改变将使用新的比例因子,但未定义现有的小部件是否会动态调整自己的大小适应新的比例因子.

A "point" is a unit of measurement equal to 1/72 inch. A scaling factor of 1.0 corresponds to 1 pixel per point, which is equivalent to a standard 72 dpi monitor. A scaling factor of 1.25 would mean 1.25 pixels per point, which is the setting for a 90 dpi monitor; setting the scaling factor to 1.25 on a 72 dpi monitor would cause everything in the application to be displayed 1.25 times as large as normal. The initial value for the scaling factor is set when the application starts, based on properties of the installed monitor, but it can be changed at any time. Measurements made after the scaling factor is changed will use the new scaling factor, but it is undefined whether existing widgets will resize themselves dynamically to accommodate the new scaling factor.

这篇关于以 4k (3840*2160) 分辨率缩放 Tkinter GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆