问题描述
所以,我正在尝试创建一个用于编写小的文本文件的程序。 经过一些测试,我发现对于分辨率低于全高清的人来说,GUI太大了。 因此,我决定创建一个按钮来更改程序的缩放比例,但是它不起作用。 这是代码
# -*- coding: utf8 -*-
from tkinter import *
from tkinter import messageBox
import os
import colorama
import requests
colorama.init()
root = Tk()
root.title('Test')
def done():
print("test")
def downscale():
root.tk.call('tk','scaling',0.5)
print("Downscaling should be working!")
downscale = Button(root,text='Can you see the done button?',command=downscale)
downscale.grid(row=1,column=1)
b = Button(root,text='Done',command=run)
b.grid(row=50,column=50)
root.mainloop()
重要的是要知道如果我使用“ root.tk.call('tk','scaling',0.5)” 通常在脚本中没有功能就可以正常工作。
解决方法
只要屏幕处于未缩放状态,请尝试使用几何图形和winfo_screennwidth()和winfo_screenheight
# -*- coding: utf8 -*-
from tkinter import *
from tkinter import messagebox
import os
import colorama
import requests
colorama.init()
root = Tk()
root.title('Test')
def done():
print("test")
def downscale():
try:
root.state('normal')
except:root.attributes('-zoomed',False)
root.geometry('{}x{}'.format(root.winfo_width()//2,root.winfo_height()//2))
downscale = Button(root,text='Can you see the done button?',command=downscale)
downscale.grid(row=1,column=1)
b = Button(root,text='Done')
b.grid(row=50,column=50)
root.mainloop()