Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Last active January 15, 2024 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/90f4007be737131a1aaa58813679e732 to your computer and use it in GitHub Desktop.
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
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