简体   繁体   中英

Creating a resizing gui button not working Tkinter

So guys I,m trying to create a program for writing a little text file. After some testing, I saw that the GUI is too large for people with a lesser resolution than Full-HD. So I decided to create a button that changes the scaling of the program but it doesn't work. Here is the code

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

It's important to know that If I use "root.tk.call('tk', 'scaling', 0.5)" in the script normally without a function it works.

Try geometry and winfo_screennwidth() and winfo_screenheight it works as long as the screen is unzoomed state

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM