Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import tkinter.ttk as ttk
- class App(tk.Tk):
- def __init__(self):
- super().__init__()
- self.rowconfigure(0, weight=1)
- self.columnconfigure(1, weight=1)
- self.title('Default Demo')
- self.geometry('800x800')
- def main():
- app = App()
- dw = tk.Toplevel()
- dw.overrideredirect(True)
- dw.wait_visibility(app)
- dw.wm_attributes('-alpha', 0.2)
- dw.wm_attributes("-topmost", True)
- dw.config(bg='#00aaff')
- dw.withdraw()
- def drag(event):
- x, y = app.winfo_pointerxy()
- width = event.x-app.anchor_x
- height = event.y-app.anchor_y
- if width < 0:
- coord_x = event.x+app.winfo_rootx()
- width = app.anchor_x - event.x
- else:
- coord_x = app.anchor_x+app.winfo_rootx()
- if coord_x+width > app.winfo_rootx()+app.winfo_width():
- width -= (coord_x+width)-(app.winfo_rootx()+app.winfo_width())
- elif x < app.winfo_rootx():
- width -= (app.winfo_rootx() - x)
- coord_x = app.winfo_rootx()
- if height < 0:
- coord_y = event.y+app.winfo_rooty()
- height = app.anchor_y - event.y
- else:
- coord_y = app.anchor_y+app.winfo_rooty()
- if coord_y+height > app.winfo_rooty()+app.winfo_height():
- height -= (coord_y+height)-(app.winfo_rooty()+app.winfo_height())
- elif y < app.winfo_rooty():
- height -= (app.winfo_rooty() - y)
- coord_y = app.winfo_rooty()
- dw.geometry(f'{width}x{height}+{coord_x}+{coord_y}')
- def button_press(event):
- dw.deiconify()
- app.anchor_x, app.anchor_y = event.x, event.y
- app.bind('<Motion>', drag)
- def button_release(event):
- dw.withdraw()
- dw.geometry('0x0+0+0')
- app.unbind('<Motion>')
- app.bind('<Button-1>', button_press)
- app.bind('<ButtonRelease-1>', button_release)
- app.mainloop()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement