Praktikum 3
Praktikum 3
Kls: BM 2B
# imports
#======================
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import Menu
from tkinter import messagebox as msg
from tkinter import Spinbox
#===================================================================
class ToolTip(object):
def __init__(self, widget, tip_text=None):
self.widget = widget
self.tip_text = tip_text
widget.bind('<Enter>', self.mouse_enter) # bind mouse events
widget.bind('<Leave>', self.mouse_leave)
def show_tooltip(self):
if self.tip_text:
x_left = self.widget.winfo_rootx() # get
widget top-left coordinates
y_top = self.widget.winfo_rooty() - 18 # place
tooltip above widget or it flickers
def hide_tooltip(self):
if self.tip_window:
self.tip_window.destroy()
#===================================================================
# Create instance
win = tk.Tk()
# Add a title
win.title("Python GUI")
# Adding a Button
action = ttk.Button(mighty, text="Click Me!", command=click_me)
action.grid(column=2, row=1)
# Spinbox callback
def _spin():
value = spin.get()
print(value)
scrol.insert(tk.INSERT, value + '\n')
# Add a Tooltip
ToolTip(spin, 'This is a Spin control')
chVarUn = tk.IntVar()
check2 = tk.Checkbutton(mighty2, text="UnChecked", variable=chVarUn)
check2.deselect()
check2.grid(column=1, row=4, sticky=tk.W)
chVarEn = tk.IntVar()
check3 = tk.Checkbutton(mighty2, text="Enabled", variable=chVarEn)
check3.deselect()
check3.grid(column=2, row=4, sticky=tk.W)
# We have also changed the callback function to be zero-based, using the list
# instead of module-level global variables
# Radiobutton Callback
def radCall():
radSel=radVar.get()
if radSel == 0: win.configure(background=colors[0]) # zero-based
elif radSel == 1: win.configure(background=colors[1]) # using list
elif radSel == 2: win.configure(background=colors[2])
# Now we are creating all three Radiobutton widgets within one loop
for col in range(3):
curRad = tk.Radiobutton(mighty2, text=colors[col], variable=radVar,
value=col, command=radCall)
curRad.grid(column=col, row=6, sticky=tk.W) # row=6