I've written a few very basic TkInter apps for testing purposes - basically filling screen with 2 colors, and it's working as expected when my screen dpi saclling is set to 100%; but when it's different it affects proportions of rectangles in my canvas. for example here I want to have exactly half of screen filed with one color and second with another:
class TkSplitScreen(object):
UPDATE_TIME = 1
def __init__(self, rect, color1, color2, communication_queue, vertical=False):
logging.info(" -- Starting TkSolidColor app")
self._communication_queue = communication_queue
self.tk = Tk()
self.tk.winfo_toplevel().title("TkSplitScreen")
gemetry = "%dx%d+%d+%d" % (rect.w, rect.h, rect.x, rect.y)
logging.info(" -- geometry: %s", gemetry)
self.tk.geometry(gemetry)
self.tk.attributes('-topmost', 1)
self.tk.state('zoomed')
self.tk.config(cursor="none") # remove cursor
self.tk.resizable(False, False)
self.tk.overrideredirect(True)
# self.tk.pack(fill=BOTH, expand=1)
hex_color1 = '#%02x%02x%02x' % color1
hex_color2 = '#%02x%02x%02x' % color2
logging.info(" -- color: %s", hex_color1)
logging.info(" -- color: %s", hex_color2)
canvas = Canvas(self.tk)
if vertical:
canvas.create_rectangle(0, 0, rect.w // 2, rect.h, fill=hex_color1, outline=hex_color1)
canvas.create_rectangle(rect.w // 2, 0, rect.w, rect.h, fill=hex_color2, outline=hex_color2)
else:
canvas.create_rectangle(0, 0, rect.w, rect.h // 2, fill=hex_color1, outline=hex_color1)
canvas.create_rectangle(0, rect.h // 2, rect.w, rect.h, fill=hex_color2, outline=hex_color2)
canvas.pack(fill=BOTH, expand=1)
self.tk.after(self.UPDATE_TIME, self.read_queue)
self.tk.mainloop()
def read_queue(self):
if not self._communication_queue.empty():
request = self._communication_queue.get()
if request == 'EXIT':
logging.info(" -- Exit request received. Closing TkSplitScreen process")
self.tk.quit()
return
self.tk.after(self.UPDATE_TIME, self.read_queue)
Where for my 4k screen i give as rect 3840x2160 (at 0, 0). Is it possible to tell OS that I don't want to scale out my TkApp? Or do I need to somehow recalculate physical resolution to some virtual points? (I was assuming that what you give to create_rectangle is in pixels not some virtual points)