正在创建一个不起作用的调整大小gui按钮Tkinter



伙计们,我正在尝试创建一个程序来编写一个小文本文件。经过一些测试,我发现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_screenwidth((和winfo_Screenright,只要屏幕处于未缩放状态,它就可以工作

# -*- 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()

最新更新