Last active
January 15, 2024 14:26
-
-
Save vigilantPotato/90f4007be737131a1aaa58813679e732 to your computer and use it in GitHub Desktop.
how to move the tkinter main window to the corner of the screen
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 tkinter | |
#Button which moves main window to the top-right of the screen | |
class MovePositionButton(tkinter.Button): | |
def __init__(self, master): | |
super().__init__( | |
master, | |
width=15, | |
text="click", | |
command=self.move_position, | |
) | |
self.master = master | |
def move_position(self): | |
screen_width = self.winfo_screenwidth() #monior width | |
main_window_width = self.master.winfo_width() #tkinter main window width | |
x = screen_width - main_window_width | |
self.master.geometry('+%d+%d' % (x, 0)) | |
def move_position2(self): | |
screen_width = self.winfo_screenwidth() #monior width | |
main_window_width = self.master.winfo_width() #tkinter main window width | |
frame = self.master.winfo_rootx() - self.master.winfo_x() #invisible frame width | |
x = screen_width - main_window_width | |
self.master.geometry('+%d+%d' % (x-frame, 0)) | |
if __name__ == "__main__": | |
root = tkinter.Tk() | |
b = MovePositionButton(root) | |
b.pack() | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment