Dialog box Examples

import tkinter.messagebox import tkinter.simpledialog import tkinter.colorchooser tkinter.messagebox.showinfo(“showinfo”, “This is an info msg”) tkinter.messagebox.showwarning(“showwarnng”,”This is a warning”) tkinter.messagebox.showerror(“showerror”, “This is an error”) isYes = tkinter.messagebox.askyesno(“askyesno”, “Continue?”) print(isYes) isOk = tkinter.messagebox.askokcancel(“askokcancel”, “OK?”) print(isOk) isYesNoCancel = tkinter.messagebox.askyesnocancel(“askyesnocancel”, “Yes, No, Cancel?”) print(isYesNoCancel) name = tkinter.simpledialog.askstring(“askstring”, “Enter your name”) print(name) age = tkinter.simpledialog.askinteger(“askinteger”, “Enter your age”) print(age) weight = tkinter.simpledialog.askfloat(“askfloat”, … Read moreDialog box Examples

Scroll bar Example

from tkinter import * # Import all definitions from tkinter class ScrollText: def __init__(self): window = Tk() # Create a window window.title(“Scroll Text Demo”) # Set title frame1 = Frame(window) frame1.pack() scrollbar = Scrollbar(frame1) scrollbar.pack(side = RIGHT, fill = Y) text = Text(frame1, width = 40, height = 10, wrap = WORD, yscrollcommand = scrollbar.set) … Read moreScroll bar Example

Animate text and Control

from tkinter import * # Import all definitions from tkinter class ControlAnimation: def __init__(self): window = Tk() # create a window window.title(“Control Animation Demo”) # Set a title self.width = 250 # width of self.canvas self.canvas = Canvas(window, bg = “white”, width = self.width, height = 50) self.canvas.pack() frame = Frame(window) frame.pack() btStop = Button(frame, … Read moreAnimate text and Control

Enlarge Shrink Circle

from tkinter import * # Import all definitons from tkinter class EnlargeShrinkCircle: def __init__(self): self.radius = 50 window = Tk() # Create a window window.title(“Control Circle Demo”) # Set a title self.canvas = Canvas(window, bg = “white”, width = 200, height = 200) self.canvas.pack() self.canvas.create_oval( 100 – self.radius, 100 – self.radius, 100 + self.radius, 100 … Read moreEnlarge Shrink Circle

Mouse Key Event Example

from tkinter import * # Import all definitions from tkinter class MouseKeyEventDemo: def __init__(self): window = Tk() # Create a window window.title(“Event Demo”) # Set a title canvas = Canvas(window, bg = “White”, width = 200, height = 100) canvas.pack() # Bind with <Button-1> event canvas.bind(“<Button-1>”, self.processMouseEvent) # Bind with <Key> event canvas.bind(“<Key>”, self.processKeyEvent) canvas.focus_set() … Read moreMouse Key Event Example

Popup Menu Example

from tkinter import * # Import all definitions from tkinter class PopupMenuDemo: def __init__(self): window = Tk() # Create a window window.title(“Popup Menu Demo”) # set title # Create a popup menu self.menu = Menu(window, tearoff = 0) self.menu.add_command(label = “Draw a line”, command = self.displayLine) self.menu.add_command(label = “Draw an oval”, command = self.displayOval) self.menu.add_command(label … Read morePopup Menu Example

Menu Example

from tkinter import * class MenuDemo: def __init__(self): window = Tk() window.title(“Menu Demo”) #Create a menu bar menubar = Menu(window) window.config(menu = menubar) # Display the menu bar # Create a pull down menu, and add it to the menu bar operationMenu = Menu(menubar, tearoff = 0) menubar.add_cascade(label = “Operation”, menu = operationMenu) operationMenu.add_command(label = … Read moreMenu Example

Place Manager

from tkinter import * # Import all definitions form tkinter class PlaceManageDemo: def __init__(self): window = Tk() # Create a window window.title(“Place Manager Demo”) # Set title Label(window, text = “Blue”, bg = “blue”).place(x = 20, y = 20) Label(window, text = “Red”, bg = “red”).place(x = 50, y = 50) Label(window, text = “Green”, … Read morePlace Manager