ctypes.windll.shcore.SetProcessDpiAwareness(True)
improves the clarity of tkinter screen on windows, but on linux ctypes has no attribute windll
, so is there an alternative solution for linux/OSX ?
The difference in the clarity with ctypes and without ctypes
here is the source code
from tkinter import *
from tkinter import ttk
import ctypes
#Increasing the clarity of tkinter screen
ctypes.windll.shcore.SetProcessDpiAwareness(True)
root = Tk()
frame = Frame(root, bd = 0, highlightthickness = 0)
frame.pack(fill = 'both', expand = True)
#Gridding frame
frame.grid_columnconfigure((0,1), weight = 1)
frame.grid_rowconfigure((0,1,2,3), weight = 1)
#Adding some widgets to frame
label_name = Label(frame, text = "Enter your name: ", bg = "#CCD1D1", fg = "black", font = ('Comic Sans', 15, 'bold'))
label_grade = Label(frame, text = "Which grade are you in? ", bg = "#CCD1D1", fg = "black", font = ('Comic Sans', 15, 'bold'))
label_school = Label(frame, text = "Enter school name: ", bg = "#CCD1D1", fg = "black", font = ('Comic Sans', 15, 'bold'))
label_name.grid(row = 0, column = 0, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
label_grade.grid(row = 1, column = 0, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
label_school.grid(row = 2, column = 0, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
#Adding some entry and combo boxes
var_name = StringVar()
var_grade = IntVar()
entry_name = Entry(frame, textvariable = var_name, font = ('Comic Sans', 15))
combo_grade = ttk.Combobox(frame, textvariable = var_grade, font = ('Comic Sans', 15), justify = CENTER)
combo_grade['values'] = tuple(str(i) for i in range(1,13))
var_school = StringVar()
entry_school = Entry(frame, textvariable = var_school, font = ('Comic Sans', 15))
entry_name.grid(row = 0, column = 1, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
combo_grade.grid(row = 1, column = 1, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
entry_school.grid(row = 2, column = 1, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
button_submit = Button(frame, text = 'SUBMIT', bg = 'green', fg = 'white', font = ('Comic Sans', 15), relief = 'ridge')
button_submit.grid(row = 3, column = 0, columnspan = 2, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
#Update frame
frame.update()
text_ = "I am adding this label because the contrast in the clarity of the tkinter screen with and without ctypes is best shown with text."
label_text = Label(frame, text = text_, fg = "black", font = ('Comic Sans', 15), wrap = frame.winfo_width())
label_text.grid(row = 4, column = 0, columnspan = 2, sticky = NSEW, padx = 5, pady = 5, ipadx = 5, ipady = 5)
root.mainloop()