Remainder Gadget
import tkinter as tk
from tkinter import messagebox
class Application:
def __init__(self):
self.root = tk.Tk()
self.root.title("Remainder Gadget")
self.root.geometry("450x80+400+300")
self.createWidget()
def createWidget(self):
global photo
photo = tk.PhotoImage(file="image//jsq.gif")
self.label_01 = tk.Label(self.root,image=photo)
self.label_01.pack(side="left")
#Dividend input
self.v1 = tk.StringVar()
self.entry_01 = tk.Entry(self.root,\
width=6,font=("Times New Roman",16),textvariable=self.v1)
self.entry_01.pack(side="left")
#module:%
self.label_02 = tk.Label(self.root,text="%")
self.label_02.pack(side="left")
#Divisor input
self.v2 = tk.StringVar()
self.entry_02 = tk.Entry(self.root,\
width=6,font=("Times New Roman",16),textvariable=self.v2)
self.entry_02.pack(side="left")
#equal label:=
self.label_03 = tk.Label(self.root,text="=")
self.label_03.pack(side="left")
#result diaplay
self.v3 = tk.StringVar()
self.entry_03 = tk.Entry(self.root,\
width=6,font=("Times New Roman",16),textvariable=self.v3)
self.entry_03.pack(side="left")
#calculate button
self.btn_01 = tk.Button(self.root,text="Calculate",width=6,height=2,command=self.clkbtn)
self.btn_01.pack(side="left",padx=10)
def clkbtn(self):
try:
v = int(self.entry_01.get()) % int(self.entry_02.get())
except ValueError:
tk.messagebox.showinfo("System Information","Wrong input,non-digit input")
except ZeroDivisionError:
tk.messagebox.showinfo("System Information","Wrong input,divisor cannot be 0")
else:
self.v3.set(v)
def run(self):
self.root.mainloop()
app = Application()
app.run()
[…] 75 Layout Manager| |____Unit 76 GUI interface example exercises| |____Unit 77 event handling| |____Unit 78 Remainder Gadget| |____Unit 79 tkinter version guessing number game| |____Unit 80 tkinter more components| |____Unit […]