tkinter_calc_ii
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tkinter_calc_ii [2024/04/20 00:36] – appledog | tkinter_calc_ii [2024/04/20 00:53] (current) – appledog | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| = TKInter Calc II | = TKInter Calc II | ||
| + | |||
| + | == Themed Widgets | ||
| + | Use ttk.button() //etc.// whenever possible. That's because ttk is the newest version. tk.button() and others are old, don't use them unless ttk. doesn' | ||
| == Binding | == Binding | ||
| Line 14: | Line 17: | ||
| button1 = ttk.Button(root, | button1 = ttk.Button(root, | ||
| - | button1.bind('< | + | button1.bind('< |
| button1.focus() | button1.focus() | ||
| button1.pack(expand=True) | button1.pack(expand=True) | ||
| + | |||
| + | root.mainloop() | ||
| + | </ | ||
| + | |||
| + | === Binding Mouse | ||
| + | Observe carefully that < | ||
| + | |||
| + | < | ||
| + | import tkinter | ||
| + | |||
| + | root = tkinter.Tk() | ||
| + | |||
| + | def right_click_handler(event): | ||
| + | # event.num == 2 is MOUSE. | ||
| + | if event.num == 2: | ||
| + | print(" | ||
| + | |||
| + | root.bind("< | ||
| + | root.bind("< | ||
| + | |||
| + | root.mainloop() | ||
| + | </ | ||
| + | |||
| + | Here, a lambda is used to handle left clicks with < | ||
| + | |||
| + | == Dragging | ||
| + | To capture a click-and-drag event use any of the < | ||
| + | |||
| + | < | ||
| + | import tkinter | ||
| + | |||
| + | root = tkinter.Tk() | ||
| + | label = tkinter.Label(root, | ||
| + | label.pack() | ||
| + | |||
| + | def drag_handler(event): | ||
| + | print(event.x, | ||
| + | |||
| + | label.bind("< | ||
| + | |||
| + | root.mainloop() | ||
| + | </ | ||
| + | |||
| + | === Hovering | ||
| + | Hovering over an element sends out two events in sequence, < | ||
| + | |||
| + | < | ||
| + | import tkinter | ||
| + | |||
| + | root = tkinter.Tk() | ||
| + | |||
| + | label = tkinter.Label(root, | ||
| + | label.bind("< | ||
| + | label.bind("< | ||
| + | label.pack() | ||
| root.mainloop() | root.mainloop() | ||
| </ | </ | ||
tkinter_calc_ii.1713573405.txt.gz · Last modified: 2024/04/20 00:36 by appledog
