Scaling of Tkinter GUI in 4k (3840*2160) resolution?
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)
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:
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.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.
Tkinter Widget Size Issues
In tkinter you can only change the size of a label with the font atribute, and same goes for the text inside the button. The button size can be changed with the width and height atribute.
from tkinter import *
window = Tk()
label = Label(text="Name", font='Helvetica 15')
entry = Entry()
button = Button(text="Submit",font ='Helvetica 15', height="3", width="10")
label.pack(pady = 5) # add pady inside the pack
entry.pack()
button.pack(pady = 5)
window.mainloop()
Related Topics
Python Re.Sub Back Reference Not Back Referencing
Reference Requirements.Txt for the Install_Requires Kwarg in Setuptools Setup.Py File
How to Create a Slug in Django
Tab Completion in Python's Raw_Input()
How to Trace the Path in a Breadth-First Search
How to Fix "Importerror: Dll Load Failed" While Importing Win32Api
Restricting the Value in Tkinter Entry Widget
How to Open Multiple Webpages in Separate Tabs Within a Browser Using Selenium-Webdriver and Python
In Python, How Does One Catch Warnings as If They Were Exceptions
How to Access a Function Inside a Function
Create a Main Loop with Tkinter
What Is the Most Efficient Way of Counting Occurrences in Pandas
How to Leave/Exit/Deactivate a Python Virtualenv