Created
June 19, 2024 20:57
-
-
Save vigilantPotato/b77130aec23e001ed27b8a2588dc7f9a to your computer and use it in GitHub Desktop.
How to move main window to monitor edge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import tkinter | |
def up_left(): | |
gap_x = root.winfo_x() - root.winfo_rootx() | |
root.geometry("+%d+%d" % (gap_x, 0)) | |
def up_right(): | |
x = root.winfo_screenwidth()- root.winfo_width() | |
gap_x = root.winfo_x() - root.winfo_rootx() | |
root.geometry("+%d+%d" % (x+gap_x, 0)) | |
def down_left(): | |
gap_x = root.winfo_x() - root.winfo_rootx() | |
gap_y = root.winfo_y() - root.winfo_rooty() | |
y = root.winfo_screenheight() - root.winfo_height() | |
root.geometry("+%d+%d" % (gap_x, y+gap_y)) | |
def down_right(): | |
gap = root.winfo_x() - root.winfo_rootx() | |
x = root.winfo_screenwidth()- root.winfo_width() | |
y = root.winfo_screenheight() - root.winfo_height() | |
gap_y = root.winfo_y() - root.winfo_rooty() | |
root.geometry("+%d+%d" % (x+gap, y+gap_y)) | |
if __name__ == "__main__": | |
ctypes.windll.shcore.SetProcessDpiAwareness(1) | |
root = tkinter.Tk() | |
#up left | |
up_left_button = tkinter.Button(root, command=up_left, text="up left", width=15, bg="lightblue") | |
up_left_button.pack() | |
#up right | |
up_right_button = tkinter.Button(root, command=up_right, text="up right", width=15, bg="lightblue") | |
up_right_button.pack() | |
#down left | |
down_left_button = tkinter.Button(root, command=down_left, text="down left", width=15, bg="lightblue") | |
down_left_button.pack() | |
#down right | |
down_right_button = tkinter.Button(root, command=down_right, text="down right", width=15, bg="lightblue") | |
down_right_button.pack() | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment