Related
I try to build a student management system while this tkinter window does not show after running following code. Can someone give some advice here? This is public source code from youtube chanel.
from tkinter import *
from tkinter import ttk
class Student:
def __init__(self,root):
self.root=root
self.root.title("student management system")
self.root.geometry("1350*700+0+0")
title=Label(self.root,text="Student Management System",bd=10,relief=GROOVE,front=("time new roman",40,"bold"),bg="yellow",fg="red")
title.pack(side=TOP,fill=X)
Manage_Frame=Frame(self.root,bd=4,relief=RIDGE,bg="crimson")
Manage_Frame.place(x=20,y=70,width=450,height=560)
#========Massage Frame===============================
Manage_Frame=Frame(self.root,bd=4,relief=RIDGE,bg="crimson")
Manage_Frame.place(x=20,y=100,width=450,height=560)
m_title=Label(Manage_Frame,text="Manage Students",bg="crimson",fg="white",front=("time new roman",30,"bold"))
m_title.grid(row=0,columnspan=2,pady=10)
lbl_roll = Label(Manage_Frame, text="Roll No.", bg="crimson", fg="white",front=("time new roman", 20, "bold"))
lbl_roll.grid(row=1, colum=0, pady=10,padx=20,sticky="w")
txt_roll = Entry(Manage_Frame,front=("time new roman", 15, "bold"),bd=5,relief=GROOVE)
txt_roll.grid(row=1, colum=2, pady=10, padx=20, sticky="w")
lbl_name = Label(Manage_Frame, text="Name", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_name.grid(row=1, colum=0, pady=10, padx=20, sticky="w")
txt_name = Entry(Manage_Frame, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_name.grid(row=2, colum=1, pady=10, padx=20, sticky="w")
lbl_Email = Label(Manage_Frame, text="Email", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_Email.grid(row=1, colum=0, pady=10, padx=20, sticky="w")
txt_Email = Entry(Manage_Frame, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Email.grid(row=3, colum=0, pady=10, padx=20, sticky="w")
lbl_Gender = Label(Manage_Frame, text="Gender", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_Gender.grid(row=4, colum=0, pady=10, padx=20, sticky="w")
combo_Gender=ttk.Combobox(Manage_Frame,front=("times new roman",20,"bold"))
combo_Gender['values']=("Male","Female","other")
combo_Gender.grid(row=4,colum=1,padx=20,pady=10)
lbl_Contact = Label(Manage_Frame, text="Contact", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_Contact.grid(row=5, colum=0, pady=10, padx=20, sticky="w")
txt_Contact = Entry(Manage_Frame, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Contact.grid(row=5, colum=1, pady=10, padx=20, sticky="w")
lbl_DOB = Label(Manage_Frame, text="DOB", bg="crimson", fg="white",front=("time new roman", 20, "bold"))
lbl_DOB.grid(row=6, colum=0, pady=10, padx=20, sticky="w")
txt_Contact = Entry(Manage_Frame, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Contact.grid(row=6, colum=1, pady=10, padx=20, sticky="w")
lbl_address = Label(Manage_Frame, text="Address", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_address.grid(row=6, colum=0, pady=10, padx=20, sticky="w")
txt_address = Entry(Manage_Frame, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_address.grid(row=6, colum=1, pady=10, padx=20, sticky="w")
#=========Button Frame=========
btn_Frame=Frame(Manage_Frame,bd=4,relief=RIDGE,bg="crimson")
btn_Frame.place(x=15, y=500, width=420)
Addbtn = Button(btn_Frame,text="add",width=10).grid(row=0,column=0,padx=10,pady=10)
Updatebtn = Button(btn_Frame, text="update", width=10).grid(row=0, column=1, padx=10, pady=10)
Deletebtn = Button(btn_Frame, text="delete", width=10).grid(row=0, column=2, padx=10, pady=10)
Clearbtn = Button(btn_Frame, text="clear", width=10).grid(row=0, column=3, padx=10, pady=10)
#=========Detail Frame=========
Detail_Frame = Frame(self.root, bd=4, relief=RIDGE, bg="crimson")
Detail_Frame.place(x=500, y=100, width=800, height=580)
lbl_search = Label(Detail_Frame, text="Search By", bg="crimson", fg="white", front=("time new roman", 20, "bold"))
lbl_search.grid(row=0, colum=0, pady=10, padx=20, sticky="w")
combo_search = ttk.Combobox(Manage_Frame,width=10,front=("times new roman", 13, "bold"),state="readonly")
combo_search['values'] = ("Roll", "Name", "contact")
combo_search.grid(row=0, colum=1, padx=20, pady=10)
txt_Search = Entry(Manage_Frame,width=15, front=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Search.grid(row=6, colum=1, pady=10, padx=20, sticky="w")
searchbtn = Button(btn_Frame, text="Search", width=10).grid(row=0, column=3, padx=10, pady=10)
showallbtn = Button(btn_Frame, text="Show All", width=10).grid(row=0, column=4, padx=10, pady=10)
#=========Table Frame=========
Table_Frame = Frame(Detail_Frame, bd=4, relief=RIDGE, bg="crimson")
Table_Frame.place(x=10, y=70, width=760, height=500)
scroll_x=Scrollbar(Table_Frame,orient=HORIZONTAL)
scroll_y = Scrollbar(Table_Frame, orient=VERTICAL)
Student_table=ttk.Treeview(Table_Frame,columns=("roll","name","email","gender","contact","dob","Address"),xscollcommand=scroll_x.set,yscollcommand=scroll_y.set)
scroll_x.pack(side=BOTTOM,fill=X)
scroll_y.pack(side=RIGHT, fill=Y)
scroll_x.config(command=Student_table.xview)
scroll_y.config(command=Student_table.xview)
Student_table.heading("roll",text="Roll")
Student_table.heading("name", text="Name")
Student_table.heading("email", text="Email")
Student_table.heading("gender", text="Gender")
Student_table.heading("Contact", text="Contact")
Student_table.heading("D.O.B", text="D.O.B")
Student_table.heading("Address", text="Address")
Student_table['show']='headings'
Student_table.pack()
root=Tk()
You have to initialize your Student object and pass root to it. Add this to the end of your code for it to run:
app=Student(root)
root.mainloop()
Your current code as is includes a lot of syntax errors that need to be fixed before running. The following should run, albeit with some visual errors:
from tkinter import *
from tkinter import ttk
class Student:
def __init__(self,root):
self.root=root
self.root.title("student management system")
self.root.geometry("1350x700")
title=Label(self.root,text="Student Management System",bd=10,relief=GROOVE,font=("time new roman",40,"bold"),bg="yellow",fg="red")
title.pack(side=TOP,fill=X)
Manage_Frame=Frame(self.root,bd=4,relief=RIDGE,bg="crimson")
Manage_Frame.place(x=20,y=70,width=450,height=560)
#========Massage Frame===============================
Manage_Frame=Frame(self.root,bd=4,relief=RIDGE,bg="crimson")
Manage_Frame.place(x=20,y=100,width=450,height=560)
m_title=Label(Manage_Frame,text="Manage Students",bg="crimson",fg="white",font=("time new roman",30,"bold"))
m_title.grid(row=0,columnspan=2,pady=10)
lbl_roll = Label(Manage_Frame, text="Roll No.", bg="crimson", fg="white",font=("time new roman", 20, "bold"))
lbl_roll.grid(row=1, column=0, pady=10,padx=20,sticky="w")
txt_roll = Entry(Manage_Frame,font=("time new roman", 15, "bold"),bd=5,relief=GROOVE)
txt_roll.grid(row=1, column=2, pady=10, padx=20, sticky="w")
lbl_name = Label(Manage_Frame, text="Name", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_name.grid(row=1, column=0, pady=10, padx=20, sticky="w")
txt_name = Entry(Manage_Frame, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_name.grid(row=2, column=1, pady=10, padx=20, sticky="w")
lbl_Email = Label(Manage_Frame, text="Email", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_Email.grid(row=1, column=0, pady=10, padx=20, sticky="w")
txt_Email = Entry(Manage_Frame, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Email.grid(row=3, column=0, pady=10, padx=20, sticky="w")
lbl_Gender = Label(Manage_Frame, text="Gender", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_Gender.grid(row=4, column=0, pady=10, padx=20, sticky="w")
combo_Gender=ttk.Combobox(Manage_Frame,font=("times new roman",20,"bold"))
combo_Gender['values']=("Male","Female","other")
combo_Gender.grid(row=4,column=1,padx=20,pady=10)
lbl_Contact = Label(Manage_Frame, text="Contact", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_Contact.grid(row=5, column=0, pady=10, padx=20, sticky="w")
txt_Contact = Entry(Manage_Frame, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Contact.grid(row=5, column=1, pady=10, padx=20, sticky="w")
lbl_DOB = Label(Manage_Frame, text="DOB", bg="crimson", fg="white",font=("time new roman", 20, "bold"))
lbl_DOB.grid(row=6, column=0, pady=10, padx=20, sticky="w")
txt_Contact = Entry(Manage_Frame, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Contact.grid(row=6, column=1, pady=10, padx=20, sticky="w")
lbl_address = Label(Manage_Frame, text="Address", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_address.grid(row=6, column=0, pady=10, padx=20, sticky="w")
txt_address = Entry(Manage_Frame, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_address.grid(row=6, column=1, pady=10, padx=20, sticky="w")
#=========Button Frame=========
btn_Frame=Frame(Manage_Frame,bd=4,relief=RIDGE,bg="crimson")
btn_Frame.place(x=15, y=500, width=420)
Addbtn = Button(btn_Frame,text="add",width=10).grid(row=0,column=0,padx=10,pady=10)
Updatebtn = Button(btn_Frame, text="update", width=10).grid(row=0, column=1, padx=10, pady=10)
Deletebtn = Button(btn_Frame, text="delete", width=10).grid(row=0, column=2, padx=10, pady=10)
Clearbtn = Button(btn_Frame, text="clear", width=10).grid(row=0, column=3, padx=10, pady=10)
#=========Detail Frame=========
Detail_Frame = Frame(self.root, bd=4, relief=RIDGE, bg="crimson")
Detail_Frame.place(x=500, y=100, width=800, height=580)
lbl_search = Label(Detail_Frame, text="Search By", bg="crimson", fg="white", font=("time new roman", 20, "bold"))
lbl_search.grid(row=0, column=0, pady=10, padx=20, sticky="w")
combo_search = ttk.Combobox(Manage_Frame,width=10,font=("times new roman", 13, "bold"),state="readonly")
combo_search['values'] = ("Roll", "Name", "contact")
combo_search.grid(row=0, column=1, padx=20, pady=10)
txt_Search = Entry(Manage_Frame,width=15, font=("time new roman", 15, "bold"), bd=5, relief=GROOVE)
txt_Search.grid(row=6, column=1, pady=10, padx=20, sticky="w")
searchbtn = Button(btn_Frame, text="Search", width=10).grid(row=0, column=3, padx=10, pady=10)
showallbtn = Button(btn_Frame, text="Show All", width=10).grid(row=0, column=4, padx=10, pady=10)
#=========Table Frame=========
Table_Frame = Frame(Detail_Frame, bd=4, relief=RIDGE, bg="crimson")
Table_Frame.place(x=10, y=70, width=760, height=500)
scroll_x=Scrollbar(Table_Frame,orient=HORIZONTAL)
scroll_y = Scrollbar(Table_Frame, orient=VERTICAL)
Student_table=ttk.Treeview(Table_Frame,columns=("roll","name","email","gender","contact","dob","Address"),xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set)
scroll_x.pack(side=BOTTOM,fill=X)
scroll_y.pack(side=RIGHT, fill=Y)
scroll_x.config(command=Student_table.xview)
scroll_y.config(command=Student_table.xview)
Student_table.heading("roll",text="Roll")
Student_table.heading("name", text="Name")
Student_table.heading("email", text="Email")
Student_table.heading("gender", text="Gender")
Student_table.heading("contact", text="Contact")
Student_table.heading("dob", text="D.O.B")
Student_table.heading("Address", text="Address")
Student_table['show']='headings'
Student_table.pack()
root=Tk()
app=Student(root)
root.mainloop()
no error shown, i just removed the scrollbar command previously added as it wasnt working. i hope someone will be able to advise how to do this as i had gone thru multiple tutorials even those advises in stack overflow. i need to be able to scroll thru the entire window, below is the full code as requested.
import tkinter as tk
from tkinter import *
import time;
import datetime
from tkinter import ttk
from PIL import ImageTk, Image
import os
root = Tk()
root.title("Fibroscan Report")
root.geometry("1000x1200")
root.iconbitmap('d:/python_file/python_gui/zaclogo.ico')
frame0 = Frame(root, width=200, height=100)
frame0.pack()
frame0.pack_propagate(0)
frame1 = Frame(frame0, width=200, height=110, padx= 5, pady=5, bd=10,relief=RIDGE)
frame1.grid(row=0, column=0)
frame2 = Frame (frame0, width=200, padx= 5, pady=5, bd=10, relief= RIDGE)
frame2.grid(row=0, column=1)
frame3 = Frame(root, width=400, height=100)
frame3.pack()
frame3.pack_propagate(0)
frame4 = Frame(frame3, width=600, height=50, padx= 5, pady=5, bd=10, relief=RIDGE)
frame4.grid(row=0, column=0)
frame4.grid_propagate(0)
frame = Frame (root, width=200, height=100, padx=5, pady=15, relief=RIDGE)
frame.pack()
frame.pack_propagate(0)
framephoto = Frame (frame)
framephoto.grid()
canvas = Canvas(framephoto, width = 800, height = 324)
canvas.grid()
img = ImageTk.PhotoImage(Image.open("metavirchart2.png"))
canvas.create_image(107, 0, anchor=NW, image=img)
canvas.image = img
frame5 = LabelFrame (root,text="Fibroscan® Score Guide",font=('arial', 10), padx= 5, pady=5, bd=10, relief= RIDGE)
frame5.pack()
frame5.pack_propagate(0)
frame6 = Frame (frame5, width=230, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame6.grid(row=1, column=0)
frame6.grid_propagate(0)
frame7 = Frame (frame5, width=230, height=115, padx= 5, pady=5, bd=10, relief= RIDGE)
frame7.grid(row=2, column=0)
frame7.grid_propagate(0)
frame8 = Frame (frame5, width=230, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame8.grid(row=3, column=0)
frame8.grid_propagate(0)
frame9 = Frame (frame5, width=230, height=100, padx= 5, pady=5, bd=10, relief= RIDGE)
frame9.grid(row=4, column=0)
frame9.grid_propagate(0)
frame10 = Frame (frame5, width=515, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame10.grid(row=1, column=1)
frame10.grid_propagate(0)
frame11 = Frame (frame5, width=515, height=115, padx= 5, pady=5, bd=10, relief= RIDGE)
frame11.grid(row=2, column=1)
frame11.grid_propagate(0)
frame12 = Frame (frame5, width=515, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame12.grid(row=3, column=1)
frame12.grid_propagate(0)
frame13 = Frame (frame5, width=515, height=100, padx= 5, pady=5, bd=10, relief= RIDGE)
frame13.grid(row=4, column=1)
frame13.grid_propagate(0)
frameguide = Frame (frame5)
frameguide.grid(row=0, column=0)
frameguide.grid_propagate(0)
frame14 = Frame (frame13)
frame14.grid(row=0, column=1)
frame14.grid_propagate(0)
identity = StringVar()
fullname = StringVar()
refdr = StringVar(root)
datescan = StringVar()
dob = StringVar()
operator = StringVar()
operator.set('Insert Operator Name')
kpa = IntVar()
metavir = StringVar()
idrtype = StringVar()
idrtxt = StringVar()
lblidentity = Label(frame1, text="Patient ID", font=('arial', 10, 'bold'))
lblidentity.grid(row=0, column=0, sticky=W)
txtidentity = Entry(frame1, width=24, textvariable=identity, font=('arial', 10))
txtidentity.grid(row=0, column=1)
lblfullname = Label(frame1, text="Patient Name", font=('arial', 10, 'bold'))
lblfullname.grid(row=1, column=0, sticky=W)
txtfullname = Entry(frame1, width=24, textvariable=fullname, font=('arial', 10))
txtfullname.grid(row=1, column=1)
lbldob = Label(frame1, text="Date of Birth", font=('arial', 10, 'bold'))
lbldob.grid(row=2, column=0, sticky=W)
txtdob = Entry(frame1, width=24,textvariable=dob, font=('arial', 10))
txtdob.grid(row=2, column=1)
lblrefdr = Label(frame1, text="Referring Doctor", font=('arial', 10, 'bold'))
lblrefdr.grid(row=3, column=0, sticky=W)
txtrefdr = ttk.Combobox(frame1, width=24,
values=[
"Operator1",
"Operator2",
"Operator3",
"Operator4",
"Operator5",
"Operator6",
"Operator7"], state = "readonly")
txtrefdr.grid(row=3, column=1)
txtrefdr.current(0)
lbldatescan = Label(frame2, text="Date of Scan", font=('arial', 10, 'bold'))
lbldatescan.grid(row=0, column=0, sticky=W)
txtdatescan = Entry(frame2, width=24, textvariable=datescan, font=('arial', 10))
txtdatescan.grid(row=0, column=1)
lblindi = Label(frame2, text="Indication", font=('arial', 10, 'bold'))
lblindi.grid(row=1, column=0, sticky=W)
txtindi = ttk.Combobox(frame2,width=24,
values=[
"Hepatitis B*",
"HCV-HIV co-infection*",
"Hepatitis C",
"Hepatitis C*",
"Chronic Cholestatic Diseases*",
"Alcohol**",
"Others",
"NAFLD***"], state="readonly")
txtindi.grid(row=1, column=1)
txtindi.current(0)
lblgender = Label(frame2, text="Gender", font=('arial', 10, 'bold'))
lblgender.grid(row=2, column=0, sticky=W)
gender = ["Male", "Female", "Unspecified"]
txtgender = ttk.Combobox(frame2, width=24,
values=gender, state="readonly")
txtgender.grid(row=2, column=1)
txtgender.current(0)
lblop = Label(frame2, text="Operator", font=('arial', 10, 'bold'))
lblop.grid(row=3, column=0, sticky=W)
txtop = Entry(frame2, width=24, textvariable=operator, font=('arial', 10))
txtop.grid(row=3, column=1)
lbltitle = Label(frame4, text="YOUR FIBROSCAN® SCORE (Median LSM) is: ")
lbltitle.grid(row=0, column=0)
lblkpa = Label(frame4, text="KPa ")
lblkpa.grid(row=0, column=2)
txtkpa = Entry(frame4, textvariable=kpa, font=('arial', 10), width=5)
txtkpa.grid(row=0, column=1)
lblmeta = Label(frame4, text=" Metavir Stage: ")
lblmeta.grid(row=0, column=3)
metavir_score = ["F0", "F0-F1", "F1", "F1-F2", "F2", "F2-F3", "F3-F4", "F4"]
txtmeta = ttk.Combobox(frame4, width=10,
values=metavir_score, textvariable=metavir, state="readonly")
txtmeta.grid(row=0, column=4)
txtmeta.current(0)
lbltitle2 = Label(frame6,
text="Underlying Liver Disease", font=('arial', 10, 'bold'))
lbltitle2.grid(sticky=E)
lbltitle3 = Label(frame7,
text="Assessment", font=('arial', 10, 'bold'))
lbltitle3.grid(sticky=W)
lbltitle4 = Label(frame8,
text="Clinical Interpretation", font=('arial', 10, 'bold'))
lbltitle4.grid(sticky=W)
lbltitle5 = Label(frame9,
text="Recommended Clinical Actions", font=('arial', 10, 'bold'))
lbltitle5.grid(sticky=W)
lbltitleudl = Label(frame10,
text="next to UDL", font=('arial', 10, 'bold'))
lbltitleudl.grid()
lbltitle3a = Label(frame11,
text="Fibroscan Median LSM =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=0, column=0, sticky =W)
txtitle3a = Entry(frame11, width=16)
txtitle3a.grid(row=0, column=1)
lbltitle3a = Label(frame11,
text="Metavir Stage =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=1, column=0, sticky=W)
txtmetasg = ttk.Combobox(frame11, width=13,
values=metavir_score, state="readonly")
txtmetasg.grid(row=1, column=1)
txtmetasg.current(0)
lbltitle3a = Label(frame11,
text="Probe Type =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=2, column=0, sticky=W)
txtmeta = ttk.Combobox(frame11, width=13,
values=[
"S",
"M",
"XL",
"Others"], state="readonly")
txtmeta.grid(row=2, column=1)
txtmeta.current(0)
lbltitle3a = Label(frame11,
text="IQR/Median =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=3, column=0, sticky=W)
txtitle3a = Entry(frame11, width=16, textvariable=idrtype)
txtitle3a.grid(row=3, column=1)
lbltitle3a = Label(frame12,
text="Significant Fibrosis =", font=('arial', 13, 'bold'))
lbltitle3a.grid(row=0, column= 0)
txtmeta = ttk.Combobox(frame12, width=10,
values=[
"Yes",
"No"], state="readonly")
txtmeta.grid(row=0, column=1)
txtmeta.current(0)
fcolumn = Frame(frame13)
fcolumn.grid()
fcolumn1 = Frame(frame13)
fcolumn1.grid(sticky=W)
txtrca = ttk.Combobox(fcolumn, width=77, height=200,
values=[
"Repeat Fibroscan in 1 year",
"Patients with significant liver fibrosis have an increased risk of complications secondary \n to liver disease and development of HCC and should be considered \n for treatment of underlying aetiology or risk factor modification.",
"In patients with advanced fibrosis or cirrhosis, regular screening \n and surveillance for HCC is also recommended.",
])
txtrca.grid(row=0, column=0)
txtrca.current(0)
txtrca.grid_propagate(0)
lbliqr = Label(fcolumn1,
text="M Probe IQR/MEDIAN =", font=('arial', 10, 'bold'))
lbliqr.grid(row=1, column=0, sticky =W)
txtiqr = Entry(fcolumn1, width=16, textvariable=idrtxt)
txtiqr.grid(row=1, column=1)
lblguide = Label(fcolumn1,
text="*AASLD, APASL, EASL Guidelines", font=('arial', 10, 'bold'))
lblguide.grid(row=2, column=0, sticky =W)
root.mainloop()
any help will be appreciated.
no hate comments pls if u cant help or dun wish to help.
Try this
from tkinter import *
scroll_bar = Scrollbar(root)
scroll_bar.pack(side=RIGHT,fill=Y)
I'm learning to make an app using python and tkinter.
and i was made a resistor calculator. the question is how to calculate the multiplication and addition of several buttons to get the value and write the total results in the resistor value entrybox?
and the worse, I don't know how to write the code here. so I gave the link.
thank you so much
enter link description here
import tkinter.messagebox
from tkinter import*
from tkinter import ttk
class Resistor:
def __init__(self, root):
self.root = root
self.root.title("Roghib Calculator Resistor")
self.root.geometry("1000x560+0+0")
self.root.configure(background="aqua")
var1 = IntVar()
var2 = IntVar()
var3 = IntVar()
var4 = IntVar()
var5 = IntVar()
var6 = IntVar()
var7 = IntVar()
var8 = IntVar()
var9 = IntVar()
var1.set("")
var2.set("")
var3.set("")
var4.set("")
var5.set("")
var6.set("")
var7.set("")
var8.set("")
var9.set("")
#value 1stband
def Band1b():
var1.set(10)
def Band1c():
var1.set(20)
def Band1d():
var1.set(30)
def Band1e():
var1.set(40)
def Band1f():
var1.set(50)
def Band1g():
var1.set(60)
def Band1h():
var1.set(70)
def Band1i():
var1.set(80)
def Band1j():
var1.set(90)
#value 2ndband
def Band2a():
var2.set(0)
def Band2b():
var2.set(1)
def Band2c():
var2.set(2)
def Band2d():
var2.set(3)
def Band2e():
var2.set(4)
def Band2f():
var2.set(5)
def Band2g():
var2.set(6)
def Band2h():
var2.set(7)
def Band2i():
var2.set(8)
def Band2j():
var2.set(9)
def hitung():
var1 = var1.get()
var2 = var2.get()
def quit():
quit = tkinter.messagebox.askyesno('Calculator Resistor', 'yakin arep metu?')
if quit > 0:
root.destroy()
return
def reset():
reset = tkinter.messagebox.askyesno('Calculator Resistor', 'yakin arep reset ?')
if reset > 0:
var1.set("")
return
#frame = Frame(root)
#frame.grid()
mainFrame = Frame(self.root, bg='olive')
mainFrame.grid()
TitleFrame = Frame(mainFrame, bg='yellow', bd=10, width=1320, padx=10, relief=RIDGE)
TitleFrame.grid(row=0, column=0, columnspan=2)
self.lblTitle = Label(TitleFrame, bg='yellow', font=('times new roman', 50, 'bold'), text="Calculator Resistor", padx=200)
self.lblTitle.grid(row=0, column=0)
ResistorFrame = Frame(mainFrame, bd=10, width=1350, padx=20, bg='dimgrey', relief=RIDGE)
ResistorFrame.grid(row=1, column=0, sticky=W)
IndicatorFrame = Frame(mainFrame, bg='yellow', bd=10, width=1350, padx=10, relief=RIDGE)
IndicatorFrame.grid(row=1, column=1, sticky=W)
#===============================================label Band Title===================================================
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'),text="1st Band")
self.lblTitle.grid(row=1, column=0)
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'), text="2nd Band")
self.lblTitle.grid(row=1, column=1)
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'), text="3rd Band")
self.lblTitle.grid(row=1, column=2)
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'), text="4th Band")
self.lblTitle.grid(row=1, column=3)
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'), text="5th Band")
self.lblTitle.grid(row=1, column=4)
self.lblTitle = Label(ResistorFrame, bg="orangered", width=8, font=('times new roman', 14, 'bold'), text="6th Band")
self.lblTitle.grid(row=1, column=5)
#option total Band
self.dis = Radiobutton(ResistorFrame, text="3 Band", font='bold', value=0, bg='dimgrey', command=self.enable_band3)
self.dis.grid(column=1, row=0)
self.en = Radiobutton(ResistorFrame, text="6 Band", font='bold', value=1, bg='dimgrey', command=self.disable_band3)
self.en.grid(column=4, row=0)
self.dis4 = Radiobutton(ResistorFrame, text="4 Band", font='bold', value=2, bg='dimgrey', command=self.enable_band4)
self.dis4.grid(column=2, row=0)
self.en4 = Radiobutton(ResistorFrame, text="5 Band", font='bold', value=3, bg='dimgrey', command=self.disable_band4)
self.en4.grid(column=3, row=0)
#1st Band
self.Band1a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='0', fg='white', bg='black')
self.Band1a.grid(row=2, column=0)
self.Band1b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1b, text='1', fg='black', bg='peru')
self.Band1b.grid(row=3, column=0)
self.Band1c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1c, text='2', fg='black', bg='red')
self.Band1c.grid(row=4, column=0)
self.Band1d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1d, text='3', fg='black', bg='orange')
self.Band1d.grid(row=5, column=0)
self.Band1e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1e, text='4', fg='black', bg='yellow')
self.Band1e.grid(row=6, column=0)
self.Band1f = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1f, text='5', fg='black', bg='green')
self.Band1f.grid(row=7, column=0)
self.Band1g = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1g, text='6', fg='black', bg='blue')
self.Band1g.grid(row=8, column=0)
self.Band1h = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1h, text='7', fg='black', bg='purple')
self.Band1h.grid(row=9, column=0)
self.Band1i = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1i, text='8', fg='black', bg='dimgrey')
self.Band1i.grid(row=10, column=0)
self.Band1j = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band1j, text='9', fg='black', bg='white')
self.Band1j.grid(row=11, column=0)
#2nd Band
self.Band2a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band2a, text='0', fg='white', bg='black')
self.Band2a.grid(row=2, column=1)
self.Band2b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), command=Band2b, text='1', fg='black', bg='peru')
self.Band2b.grid(row=3, column=1)
self.Band2c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='2', fg='black', bg='red')
self.Band2c.grid(row=4, column=1)
self.Band2d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='3', fg='black', bg='orange')
self.Band2d.grid(row=5, column=1)
self.Band2e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='4', fg='black', bg='yellow')
self.Band2e.grid(row=6, column=1)
self.Band2f = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='5', fg='black', bg='green')
self.Band2f.grid(row=7, column=1)
self.Band2g = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='6', fg='black', bg='blue')
self.Band2g.grid(row=8, column=1)
self.Band2h = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='7', fg='black', bg='purple')
self.Band2h.grid(row=9, column=1)
self.Band2i = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='8', fg='black', bg='dimgrey')
self.Band2i.grid(row=10, column=1)
self.Band2j = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='9', fg='black', bg='white')
self.Band2j.grid(row=11, column=1)
#3rd Band
self.Band3a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='0', fg='white', bg='black')
self.Band3a.grid(row=2, column=2)
self.Band3b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='1', fg='black', bg='peru')
self.Band3b.grid(row=3, column=2)
self.Band3c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='2', fg='black', bg='red')
self.Band3c.grid(row=4, column=2)
self.Band3d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='3', fg='black', bg='orange')
self.Band3d.grid(row=5, column=2)
self.Band3e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='4', fg='black', bg='yellow')
self.Band3e.grid(row=6, column=2)
self.Band3f = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='5', fg='black', bg='green')
self.Band3f.grid(row=7, column=2)
self.Band3g = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='6', fg='black', bg='blue')
self.Band3g.grid(row=8, column=2)
self.Band3h = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='7', fg='black', bg='purple')
self.Band3h.grid(row=9, column=2)
self.Band3i = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='8', fg='black', bg='dimgrey')
self.Band3i.grid(row=10, column=2)
self.Band3j = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='9', fg='black', bg='white')
self.Band3j.grid(row=11, column=2)
#4th Band
self.Band4a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x1', fg='white', bg='black')
self.Band4a.grid(row=2, column=3)
self.Band4b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x10', fg='black', bg='peru')
self.Band4b.grid(row=3, column=3)
self.Band4c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x100', fg='black', bg='red')
self.Band4c.grid(row=4, column=3)
self.Band4d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x1k', fg='black', bg='orange')
self.Band4d.grid(row=5, column=3)
self.Band4e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x10k', fg='black', bg='yellow')
self.Band4e.grid(row=6, column=3)
self.Band4f = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x100k', fg='black', bg='green')
self.Band4f.grid(row=7, column=3)
self.Band4g = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x1M', fg='black', bg='blue')
self.Band4g.grid(row=8, column=3)
self.Band4h = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x10M', fg='black', bg='purple')
self.Band4h.grid(row=9, column=3)
self.Band4a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x0.01', fg='black', bg='darkgray')
self.Band4a.grid(row=10, column=3)
self.Band4b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='x0.1', fg='black', bg='darkgoldenrod')
self.Band4b.grid(row=11, column=3)
#5thband
self.Band5a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='1%', fg='black', bg='peru')
self.Band5a.grid(row=3, column=4)
self.Band5b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='2%', fg='black', bg='red')
self.Band5b.grid(row=4, column=4)
self.Band5c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='0.5%', fg='black', bg='green')
self.Band5c.grid(row=7, column=4)
self.Band5d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='0.25%', fg='black', bg='blue')
self.Band5d.grid(row=8, column=4)
self.Band5e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='0.1%', fg='black', bg='purple')
self.Band5e.grid(row=9, column=4)
self.Band5g = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='10%', fg='black', bg='darkgray')
self.Band5g.grid(row=10, column=4)
self.Band5f = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='5%', fg='black', bg='darkgoldenrod')
self.Band5f.grid(row=11, column=4)
#6th Band
self.Band6a = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='250ppm/K', fg='white', bg='black')
self.Band6a.grid(row=2, column=5)
self.Band6b = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='100ppm/K', fg='black', bg='peru')
self.Band6b.grid(row=3, column=5)
self.Band6c = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='50ppm/K', fg='black', bg='red')
self.Band6c.grid(row=4, column=5)
self.Band6d = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='15ppm/K', fg='black', bg='orange')
self.Band6d.grid(row=5, column=5)
self.Band6e = Button(ResistorFrame, width=8, font=('times new roman', 14, 'bold'), text='25ppm/K', fg='black', bg='yellow')
self.Band6e.grid(row=6, column=5)
#Indicator Frame
self.lblFirst = Label(IndicatorFrame, bg='yellow', font=('times new roman', 15, 'bold'), text="Resistor Value")
self.lblFirst.grid(row=0, column=0, sticky=W, padx=10)
self.txtFirst = Entry(IndicatorFrame, width=16, font=('times new roman', 15, 'bold'), textvariable=var1)
self.txtFirst.grid(row=0, column=1, pady=3, columnspan=3)
self.lbltole = Label(IndicatorFrame, bg='yellow', font=('times new roman', 15, 'bold'), text="Tolerance")
self.lbltole.grid(row=1, column=0, sticky=W, padx=10)
self.txtSecond = Entry(IndicatorFrame, width=16, font=('times new roman', 15, 'bold'), textvariable=var8)
self.txtSecond.grid(row=1, column=1, pady=10, columnspan=3)
self.temp = Label(IndicatorFrame, bg='yellow', font=('times new roman', 15, 'bold'), text="Temp. Coefficient")
self.temp.grid(row=2, column=0, sticky=W, padx=10)
self.txtthird = Entry(IndicatorFrame, width=16, font=('times new roman', 15, 'bold'), textvariable=var8)
self.txtthird.grid(row=2, column=1, pady=10, columnspan=5)
btnQuit = Button(IndicatorFrame, height=2, text="QUIT", width=8, command=quit)
btnQuit.grid(column=1, row=3, pady=10)
btnReset = Button(IndicatorFrame, height=2, text="RESET", command=reset, width=8)
btnReset.grid(column=2, row=3, pady=10)
btnHitung = Button(IndicatorFrame, height=2, command=hitung, text="HITUNG", width=8)
btnHitung.grid(column=3, row=3, pady=10)
def enable_band3(self):
if self.en == 0:
self.Band3a.configure(state='normal')
self.Band3b.configure(state='normal')
self.Band3c.configure(state='normal')
self.Band3d.configure(state='normal')
self.Band3e.configure(state='normal')
self.Band3f.configure(state='normal')
self.Band3g.configure(state='normal')
self.Band3h.configure(state='normal')
self.Band3i.configure(state='normal')
self.Band3j.configure(state='normal')
self.Band5a.configure(state='normal')
self.Band5b.configure(state='normal')
self.Band5c.configure(state='normal')
self.Band5d.configure(state='normal')
self.Band5e.configure(state='normal')
self.Band5f.configure(state='normal')
self.Band5g.configure(state='normal')
self.Band6a.configure(state='normal')
self.Band6b.configure(state='normal')
self.Band6c.configure(state='normal')
self.Band6d.configure(state='normal')
else:
self.Band1a.configure(state='disabled')
self.Band3a.configure(state='disabled')
self.Band3b.configure(state='disabled')
self.Band3c.configure(state='disabled')
self.Band3d.configure(state='disabled')
self.Band3e.configure(state='disabled')
self.Band3f.configure(state='disabled')
self.Band3g.configure(state='disabled')
self.Band3h.configure(state='disabled')
self.Band3i.configure(state='disabled')
self.Band3j.configure(state='disabled')
self.Band5a.configure(state='disabled')
self.Band5b.configure(state='disabled')
self.Band5c.configure(state='disabled')
self.Band5d.configure(state='disabled')
self.Band5e.configure(state='disabled')
self.Band5f.configure(state='disabled')
self.Band5g.configure(state='disabled')
self.Band6a.configure(state='disabled')
self.Band6b.configure(state='disabled')
self.Band6c.configure(state='disabled')
self.Band6d.configure(state='disabled')
self.Band6e.configure(state='disabled')
def disable_band3(self):
if self.dis != 0:
self.Band1a.configure(state='normal')
self.Band3a.configure(state='normal')
self.Band3b.configure(state='normal')
self.Band3c.configure(state='normal')
self.Band3d.configure(state='normal')
self.Band3e.configure(state='normal')
self.Band3f.configure(state='normal')
self.Band3g.configure(state='normal')
self.Band3h.configure(state='normal')
self.Band3i.configure(state='normal')
self.Band3j.configure(state='normal')
self.Band5a.configure(state='normal')
self.Band5b.configure(state='normal')
self.Band5c.configure(state='normal')
self.Band5d.configure(state='normal')
self.Band5e.configure(state='normal')
self.Band5f.configure(state='normal')
self.Band5g.configure(state='normal')
self.Band6a.configure(state='normal')
self.Band6b.configure(state='normal')
self.Band6c.configure(state='normal')
self.Band6d.configure(state='normal')
self.Band6e.configure(state='normal')
def enable_band4(self):
if self.en4 == 1:
self.Band3a.configure(state='disabled')
self.Band3b.configure(state='disabled')
self.Band3c.configure(state='disabled')
self.Band3d.configure(state='disabled')
self.Band3e.configure(state='disabled')
self.Band3f.configure(state='disabled')
self.Band3g.configure(state='disabled')
self.Band3h.configure(state='disabled')
self.Band3i.configure(state='disabled')
self.Band3j.configure(state='disabled')
self.Band6a.configure(state='disabled')
self.Band6b.configure(state='disabled')
self.Band6c.configure(state='disabled')
self.Band6d.configure(state='disabled')
else:
self.Band3a.configure(state='disabled')
self.Band3b.configure(state='disabled')
self.Band3c.configure(state='disabled')
self.Band3d.configure(state='disabled')
self.Band3e.configure(state='disabled')
self.Band3f.configure(state='disabled')
self.Band3g.configure(state='disabled')
self.Band3h.configure(state='disabled')
self.Band3i.configure(state='disabled')
self.Band3j.configure(state='disabled')
self.Band5a.configure(state='normal')
self.Band5b.configure(state='normal')
self.Band5c.configure(state='normal')
self.Band5d.configure(state='normal')
self.Band5e.configure(state='normal')
self.Band5f.configure(state='normal')
self.Band5g.configure(state='normal')
self.Band6a.configure(state='disabled')
self.Band6b.configure(state='disabled')
self.Band6c.configure(state='disabled')
self.Band6d.configure(state='disabled')
def disable_band4(self):
if self.dis4 != 1:
self.Band1a.configure(state='normal')
self.Band3a.configure(state='normal')
self.Band3b.configure(state='normal')
self.Band3c.configure(state='normal')
self.Band3d.configure(state='normal')
self.Band3e.configure(state='normal')
self.Band3f.configure(state='normal')
self.Band3g.configure(state='normal')
self.Band3h.configure(state='normal')
self.Band3i.configure(state='normal')
self.Band3j.configure(state='normal')
self.Band5a.configure(state='normal')
self.Band5b.configure(state='normal')
self.Band5c.configure(state='normal')
self.Band5d.configure(state='normal')
self.Band5e.configure(state='normal')
self.Band5f.configure(state='normal')
self.Band5g.configure(state='normal')
self.Band6a.configure(state='normal')
self.Band6b.configure(state='normal')
self.Band6c.configure(state='normal')
self.Band6d.configure(state='normal')
self.Band6a.configure(state='disabled')
self.Band6b.configure(state='disabled')
self.Band6c.configure(state='disabled')
self.Band6d.configure(state='disabled')
self.Band6e.configure(state='disabled')
if __name__=='__main__':
root = Tk()
application = Resistor(root)
root.mainloop()
In functions SetBand after varX.set() you can execute function which calculate value and update it in Entry.
Other changes (which reduced lines of code):
I keep colors and buttons text on lists so I can use for-loop (with zip() and enumerate()) to generate buttons. I keep buttons on list so later I can use for-loop to change states in buttons.
In command= I use lamba so I can assign the same function with different arguments
Full working code but I'm not sure if all works as expected.
import tkinter.messagebox
import tkinter as tk
from tkinter import ttk
class Resistor:
def set_band1(self, value):
self.var_band1.set(value)
self.update_labels()
def set_band2(self, value):
self.var_band2.set(value)
self.update_labels()
def set_band3(self, value):
self.var_band3.set(value)
self.update_labels()
def set_band4(self, value):
self.var_band4.set(value)
self.update_labels()
def set_band5(self, value):
self.var_band5.set(value)
self.update_labels()
def set_band6(self, value):
self.var_band6.set(value)
self.update_labels()
def update_labels(self):
v1 = self.var_band1.get()*100
v2 = self.var_band2.get()*10
v3 = self.var_band3.get()*1
value = (v1+v2+v3) * self.var_band4.get()
self.var_resistance.set(value)
value = self.var_band5.get()
self.var_tolerance.set(value)
value = self.var_band6.get()
self.var_temp.set(value)
def hitung(self):
var1 = self.var_band1.get()
var2 = self.var_band2.get()
def quit(self):
result = tkinter.messagebox.askyesno('Calculator Resistor', 'yakin arep metu?')
if result:
root.destroy()
def reset(self):
result = tkinter.messagebox.askyesno('Calculator Resistor', 'yakin arep reset ?')
if result:
self.var_band1.set(0)
def __init__(self, root):
self.root = root
self.root.title("Roghib Calculator Resistor")
#self.root.geometry("1000x560+0+0")
self.root.configure(background="aqua")
self.var_band1 = tk.IntVar(value=0)
self.var_band2 = tk.IntVar(value=0)
self.var_band3 = tk.IntVar(value=0)
self.var_band4 = tk.IntVar(value=1)
self.var_band5 = tk.StringVar(value='')
self.var_band6 = tk.StringVar(value='')
self.var_resistance = tk.StringVar(value='0')
self.var_tolerance = tk.StringVar(value='0')
self.var_temp = tk.StringVar(value='0')
# === Frames ===
main_frame = tk.Frame(self.root, bg='olive')
main_frame.grid()
title_frame = tk.Frame(main_frame, bg='yellow', bd=10, width=1320, padx=10, relief='ridge')
title_frame.grid(row=0, column=0, columnspan=2)
self.lblTitle = tk.Label(title_frame, bg='yellow', font=('times new roman', 50, 'bold'), text="Calculator Resistor", padx=200)
self.lblTitle.grid(row=0, column=0)
resistor_frame = tk.Frame(main_frame, bd=10, width=1350, padx=20, bg='dimgrey', relief='ridge')
resistor_frame.grid(row=1, column=0, sticky='w')
indicator_frame = tk.Frame(main_frame, bg='yellow', bd=10, width=1350, padx=10, relief='ridge')
indicator_frame.grid(row=1, column=1, sticky='w')
# === label Band Title ===
FONT1 = ('times new roman', 14, 'bold')
FONT2 = ('times new roman', 15, 'bold')
for i, name in enumerate(('1st', '2nd', '3rd', '4th', '5th', '6th')):
label = tk.Label(resistor_frame, text="{} Band".format(name), bg="orangered", width=8, font=FONT1)
label.grid(row=1, column=i)
#option total Band
options = {'font': 'bold', 'bg': 'dimgrey'}
self.dis = tk.Radiobutton(resistor_frame, text="3 Band", value=0, command=self.enable_band3, **options)
self.dis.grid(column=1, row=0)
self.dis4 = tk.Radiobutton(resistor_frame, text="4 Band", value=2, command=self.enable_band4, **options)
self.dis4.grid(column=2, row=0)
self.en4 = tk.Radiobutton(resistor_frame, text="5 Band", value=3, command=self.disable_band4, **options)
self.en4.grid(column=3, row=0)
self.en = tk.Radiobutton(resistor_frame, text="6 Band", value=1, command=self.disable_band3, **options)
self.en.grid(column=4, row=0)
colors_1 = (
('white', 'black'),
('black', 'peru'),
('black', 'red'),
('black', 'orange'),
('black', 'yellow'),
('black', 'green'),
('black', 'blue'),
('black', 'purple'),
('black', 'dimgrey'),
('black', 'white'),
)
colors_2 = (
('white', 'black'),
('black', 'peru'),
('black', 'red'),
('black', 'orange'),
('black', 'yellow'),
('black', 'green'),
('black', 'blue'),
('black', 'purple'),
('black', 'darkgray'),
('black', 'darkgoldenrod'),
)
# === 1st Band ===
self.buttons_band1 = []
for i, color in enumerate(colors_1):
button = tk.Button(resistor_frame, text=str(i), command=lambda x=i:self.set_band1(x), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=0)
self.buttons_band1.append(button)
# === 2nd Band ===
self.buttons_band2 = []
for i, color in enumerate(colors_1):
button = tk.Button(resistor_frame, text=str(i), command=lambda x=i:self.set_band2(x), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=1)
self.buttons_band2.append(button)
# === 3rd Band ===
self.buttons_band3 = []
for i, color in enumerate(colors_1):
button = tk.Button(resistor_frame, text=str(i), command=lambda x=i:self.set_band3(x), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=2)
self.buttons_band3.append(button)
# === 4th Band ===
values = (
('x1', 1), ('x10', 10), ('x100', 100),
('x1k', 1000), ('x10k', 10000), ('x100k', 100000),
('x1M', 1000000), ('x10M', 10000000), ('x100M', 100000000),
('x0.01', 0.01), ('x0.1M', 0.1)
)
self.buttons_band4 = []
for i, (color, value) in enumerate(zip(colors_2, values)):
if value:
button = tk.Button(resistor_frame, text=value[0], command=(lambda x=value[1]:self.set_band4(x)), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=3)
self.buttons_band4.append(button)
# === 5th Band ===
values = (
None, ('1%', 0.01), ('2%', 0.02),
None, None, ('0.5%', 0.005), ('0.25%', 0.0025), ('0.1%', 0.001),
('10%', 0.1), ('5%', 0.05),
)
self.buttons_band5 = []
for i, (color, value) in enumerate(zip(colors_2, values)):
if value:
button = tk.Button(resistor_frame, text=value[0], command=(lambda x=value[0]:self.set_band5(x)), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=4)
self.buttons_band5.append(button)
# === 6th Band ===
values = (
'250ppm/K', '100ppm/K', '50ppm/K', '15ppm/K', '25ppm/K',
)
self.buttons_band6 = []
for i, (color, value) in enumerate(zip(colors_2, values)):
if value:
button = tk.Button(resistor_frame, text=value, command=(lambda x=value:self.set_band6(x)), width=8, font=FONT1, fg=color[0], bg=color[1])
button.grid(row=i+2, column=5)
self.buttons_band6.append(button)
# === Indicator Frame ===
label = tk.Label(indicator_frame, text="Resistor Value", bg='yellow', font=FONT2)
label.grid(row=0, column=0, sticky='w', padx=10)
entry = tk.Entry(indicator_frame, width=16, font=FONT2, textvariable=self.var_resistance)
entry.grid(row=0, column=1, pady=3, columnspan=3)
label = tk.Label(indicator_frame, text="Tolerance", bg='yellow', font=FONT2)
label.grid(row=1, column=0, sticky='w', padx=10)
entry = tk.Entry(indicator_frame, width=16, font=FONT2, textvariable=self.var_tolerance)
entry.grid(row=1, column=1, pady=10, columnspan=3)
label = tk.Label(indicator_frame, text="Temp. Coefficient", bg='yellow', font=FONT2)
label.grid(row=2, column=0, sticky='w', padx=10)
entry = tk.Entry(indicator_frame, width=16, font=FONT2, textvariable=self.var_temp)
entry.grid(row=2, column=1, pady=10, columnspan=5)
button = tk.Button(indicator_frame, text="QUIT", command=self.quit, width=8, height=2)
button.grid(column=1, row=3, pady=10)
button = tk.Button(indicator_frame, text="RESET", command=self.reset, width=8, height=2)
button.grid(column=2, row=3, pady=10)
button = tk.Button(indicator_frame, text="HITUNG", command=self.hitung, width=8, height=2)
button.grid(column=3, row=3, pady=10)
def enable_band3(self):
if self.en == 0:
value = 'normal'
else:
value = 'disabled'
for button in self.buttons_band3:
button.configure(state=value)
for button in self.buttons_band5:
button.configure(state=value)
for button in self.buttons_band6:
button.configure(state=value)
def disable_band3(self):
if self.dis != 0:
value = 'normal'
for button in self.buttons_band3:
button.configure(state=value)
for button in self.buttons_band5:
button.configure(state=value)
for button in self.buttons_band6:
button.configure(state=value)
def enable_band4(self):
if self.en4 != 1:
value = 'normal'
for button in self.buttons_band5:
button.configure(state=value)
value = 'disable'
for button in self.buttons_band3:
button.configure(state=value)
for button in self.buttons_band6:
button.configure(state=value)
def disable_band4(self):
if self.dis4 != 1:
value = 'normal'
for button in self.buttons_band3:
button.configure(state=value)
for button in self.buttons_band5:
button.configure(state=value)
value = 'disable'
for button in self.buttons_band6:
button.configure(state=value)
if __name__=='__main__':
root = tk.Tk()
application = Resistor(root)
root.mainloop()
BTW: If I would keep IntVar on list then I could use one set_band(self, number, value) instead of set_band1(self, value), set_band2(self, value), etc.
I want my text in to be shifted to the left, but justify, side nor anchor do this. I am using tkinter and python 3.
queue_frame = tk.Frame(master_frame)
queue_frame.pack()
queue_hash = tk.Label(queue_frame, text='#', width=3, font=('Arial', 14, 'bold'))
queue_hash.pack(side=tk.LEFT)
queue_name = tk.Label(queue_frame, text='Name', width=15, justify=tk.LEFT, font=('Arial', 14, 'bold'))
queue_name.pack(side=tk.LEFT)
queue_question_asked = tk.Label(queue_frame, text='Question Asked', width=25, font=('Arial', 14, 'bold'), justify=tk.LEFT)
queue_question_asked.pack(side=tk.LEFT)
queue_time = tk.Label(queue_frame, text='Time', width=15, font=('Arial', 14, 'bold'), justify=tk.LEFT)
queue_time.pack(side=tk.LEFT)
Thank you very much.
Here is a reference to Label options http://effbot.org/tkinterbook/label.htm
Use anchor with the option 'w' and if you add relief = raised you can see the relative location of the text within the label.
import tkinter as tk
master_frame = tk.Tk()
queue_frame = tk.Frame(master_frame)
queue_frame.pack()
queue_hash = tk.Label(queue_frame,
text='#',
width=3,
relief='raised')
queue_hash.pack(side=tk.LEFT)
queue_name = tk.Label(queue_frame,
text='Name',
width=15,
anchor='w',
relief='raised')
queue_name.pack(side=tk.LEFT)
queue_question_asked = tk.Label(queue_frame,
text='Question Asked',
width=25,
relief='raised',
anchor='w')
queue_question_asked.pack(side=tk.LEFT)
queue_time = tk.Label(queue_frame,
text='Time',
width=15,
relief='raised',
anchor='w')
queue_time.pack(side=tk.LEFT)
master_frame.mainloop()
I'm trying to make a python(2.7) Cafe System. I created most of the functions just one function It is supposed to after I click the check button to open up the entry. Just when I click the check box button it won't open does anyone know why?
from Tkinter import *
import random
import time
import datetime
root = Tk()
root.geometry("1350x750+0+0")
root.title("Cafe Management System")
root.configure(background='black')
Tops = Frame(root, width=1350, height=100, bd=14, relief="raise")
Tops.pack(side=TOP)
f1 = Frame(root, width=900, height=650, bd=8, relief="raise")
f1.pack(side=LEFT)
f2 = Frame(root, width=440, height=650, bd=8, relief="raise")
f2.pack(side=RIGHT)
f1a = Frame(f1, width=900, height=320, bd=6, relief="raise")
f1a.pack(side=TOP)
f2a = Frame(f1, width=900, height=320, bd=6, relief = "raise")
f2a.pack(side=BOTTOM)
ft2 = Frame(f2, width= 440,height=450,bd=12,relief="raise")
ft2.pack(side=TOP)
fb2 = Frame(f2, width=440, height=250, bd=16, relief="raise")
fb2.pack(side=BOTTOM)
f1aa = Frame(f1a, width=400, height=330, bd=16, relief="raise")
f1aa.pack(side=LEFT)
f1ab = Frame(f1a, width=400, height=330, bd=16, relief="raise")
f1ab.pack(side=RIGHT)
f2aa = Frame(f2a, width=450, height=330, bd=14, relief="raise")
f2aa.pack(side=LEFT)
f2ab = Frame(f2a, width=450, height=330, bd=14, relief="raise")
f2ab.pack(side=RIGHT)
Tops.configure(background='black')
f1.configure(background='black')
f2.configure(background='black')
lblInfo = Label(Tops, font=('arial', 70, 'bold'), text="Cafe Management")
lblInfo.grid(row=0, column=0)
#===============================Functions============================
def qExit():
root.destroy()
def Reset():
PaidTax.set("")
SubTotal.set("")
TotalCost.set("")
CostofDrinks.set("")
CostofCakes.set("")
ServiceCharge.set("")
txtReciept.delete("1.0",END)
E_Latta.set("0")
E_Coffee_Cake.set("0")
#===============================Variables============================
var1=IntVar()
DateofOrder = StringVar()
Reciept_Ref = StringVar()
PaidTax = StringVar()
SubTotal = StringVar()
TotalCost = StringVar()
CostofCakes=StringVar()
CostofDrinks=StringVar()
ServiceCharge=StringVar()
E_Latta = StringVar()
E_Coffee_Cake=StringVar()
E_Coffee_Cake.set("0")
DateofOrder.set(time.strftime("%H:%M:%S"))
#=========================DRINKS======================
Latta = Checkbutton(f1ab, text="Latte \t", variable = var1, onvalue = 1, offvalue = 0,
font=('arial',18,'bold')).grid(row=0, sticky=W)
#=======================Enter Widget For Cakes=================
txtLatta = Entry(f1aa, font=('arial', 16, 'bold'), bd=8, width=6, justify='left', textvariable=E_Coffee_Cake, state=DISABLED)
txtLatta.grid(row=0, column=1)
#===========================================================Check b
def chkbutton_value():
if (var1.get() == 1):
txtLatta.configure(state=NORMAL)
elif var1.get()==0:
txtLatta.configure(state=DISABLED)
E_Latta.set("0")
#===========================================================Check btns
var1.set(0)
txtLatta.configure(state=DISABLED)
#=======================================Infomation====
lblReciept = Label(ft2, font=('arial', 12, 'bold'), text="Reciept", bd=2).grid(row=0,column=0,sticky=W,)
txtReciept = Text(fb2,font=('arial',11,'bold'), bd=8, width=59)
txtReciept.grid(row=1, column=0)
#========================================Items
lblCostofDrinks=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Drinks", bd=8)
lblCostofDrinks.grid(row=0, column=0, sticky=W)
txtCostofDrinks=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2,justify='left', textvariable=CostofDrinks)
txtCostofDrinks.grid(row=0, column=1, sticky=W)
lblCostofCakes=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Cakes", bd=8)
lblCostofCakes.grid(row=1, column=0, sticky=W)
txtCostofCakes=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2,justify='left',textvariable=CostofCakes)
txtCostofCakes.grid(row=1, column=1, sticky=W)
lblServiceCharge=Label(f2aa,font=('arial', 16, 'bold'), text="Service Charge", bd=8)
lblServiceCharge.grid(row=2, column=0, sticky=W)
txtServiceCharge=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left')
txtServiceCharge.grid(row=2, column=1, sticky=W)
#========================================Payment Info===================================
lblPaidTax=Label(f2ab,font=('arial', 16, 'bold'), text="Tax", bd=8)
lblPaidTax.grid(row=0, column=0, sticky=W)
txtPaidTax=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=PaidTax)
txtPaidTax.grid(row=0, column=1, sticky=W)
lblSubTotal=Label(f2ab,font=('arial', 16, 'bold'), text="Sub Total", bd=8)
lblSubTotal.grid(row=1, column=0, sticky=W)
txtSubTotal=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=SubTotal)
txtSubTotal.grid(row=1, column=1, sticky=W)
lblTotalCost=Label(f2ab,font=('arial', 16, 'bold'), text="Total", bd=8)
lblTotalCost.grid(row=2, column=0, sticky=W)
txtTotalCost=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=TotalCost)
txtTotalCost.grid(row=2, column=1, sticky=W)
CostofDrinks.set("")
CostofCakes.set("")
#========================================Buttons=======================
btnTotal = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Total ").grid(row=3, column=1)
btnReciept = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Reciept ").grid(row=3, column=2)
btnReset = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Reset ", command=Reset).grid(row=3, column=3)
btnExit = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Exit ",command=qExit).grid(row=3, column=4)
root.mainloop()
After taking some time on this one I noticed several formatting problems. However I am just going to answer the question about the checkbox issue.
You need to change your creation of each checkbox to include command = chkbutton_value.
Take a look at how I would create your Latta check button.
Latta = Checkbutton(f1ab, text="Latte \t", onvalue = 1, offvalue = 0,
font=('arial',18,'bold'), variable = var1, command = chkbutton_value)
NOTE: you need to make sure the function chkbutton_value(): is before the creation of your check buttons because you will get a error otherwise. NameError: name 'chkbutton_value' is not defined