Python Forum
Radio butto to enable/disable combo box in Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Radio butto to enable/disable combo box in Tkinter
#1
I have two rows of combo boxes representing two different groups. the user needs to select either of the group and then choose different values from these drop down boxes. I have used radio buttons to choose the group. however Its not working out . One group remains permanently disabled. I am unable to figure out where I am making a mistake. Can someone please help.Here is my code.
from tkinter import *
import tkinter as tk
import datetime as dt
from tkinter import ttk
from tkcalendar import DateEntry
import mysql.connector
from tkinter import messagebox

#connect clinicmaster database labname,workrequire,materials, tables to combobox
mydb= mysql.connector.connect(host="localhost",user="root", password="mudit",database="Clinicmaster",auth_plugin="mysql_native_password")
cursor=mydb.cursor()
options=[]
sql="select labname,lemail from clinicmaster"
cursor.execute(sql)
labname=cursor.fetchall()
for i in labname:
    options.append(str(i[0]))

workr=[]
sql="select work from workrequired"
cursor.execute(sql)
workreq=cursor.fetchall()
for i in workreq:
    workr.append(str(i[0]))
    
mater=[]
sql="select material from materials"
cursor.execute(sql)
material=cursor.fetchall()
for i in material:
    mater.append(str(i[0]))
#print(labname)

root = Tk()
root.title("Lab Order Form")
#photo=PhotoImage(file="C:\\Users\\INDIAN\\Desktop\\python exercises\\order form\\crown2.png")
#label = Label(root,image = photo,bg="light blue")
#label.image = photo # keep a reference!
#label.grid(row=7,column=3,columnspan=20,sticky=tk.E,rowspan=30)
#order date as current date
d = f'{dt.datetime.now():%a, %b %d %Y}'

#delivery date calender picker
sel=tk.StringVar()
cal = DateEntry(root,selectmode = 'day',date_pattern="dd-mm-y", 
background='darkblue', foreground='white', borderwidth=2)
def my_upd(*args):
    l1.config(text=cal.get_date())
    #l1.config(text=sel.get())
sel.trace('w',root)
#,cal.pack(padx=10, pady=10)

                       


def getvals():
    print("Submitting form")

    print(f"{labvalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(), reqdatevalue.get(),toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toohreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()} ",d)
    



    with open("records.txt", "a") as f:
        f.write(f"{labvalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(),reqdatevalue.get(), toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toohreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()}\n")

# function to write to orderform table in database
def order():
    
    orderdaate=d
    deliverydate=cal.get_date()
    labname=labvalue.get()
    patient=patientnamevalue.get()
    ptage=patientagevalue.get()
    ptsex=patientsexvalue.get()
    workrequired=workvalue.get()
    tooth=toothnumbervalue.get()
    material=materialvalue.get()
    incisal=incisalvalue.get()
    middle=middlevalue.get()
    cervical=cervicalvalue.get()
    value=valuevalue.get()
    chroma=chromavalue.get()
    hue=huevalue.get()
    metalcoping=labservicevalue.get()
    toohreduction=toohreductionvalue.get()
    reductioncoping=reductioncopingvalue.get()
    sback=sendbackvalue.get()
    sql="INSERT INTO orderform(orderdaate,deliverydate,labname,patient,ptage,ptsex,workrequired,tooth,material,incisal,middle,cervical,value,chroma,hue,metalcoping,toohreduction,reductioncoping,sback)" "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    cursor.execute(sql,(orderdaate,deliverydate,labname,patient,ptage,ptsex,workrequired,tooth,material,incisal,middle,cervical,value,chroma,hue,metalcoping,toohreduction,reductioncoping,sback))
    mydb.commit()
    print("DONE")
   
    return True



root.geometry("1200x700")
root.configure(background='light blue')

Label(root, text="Arora Dental Care\n Lab Work Order\n Crown ", font="comicsansms 13 bold",bg="light blue", pady=15).grid(row=0, column=2)

def openNewWindow():
    global newWindow
    try:
        if newWindow.state()=="normal":newWindow.focus()
    except:
         newWindow = Toplevel(root)
         newWindow.title("Add Work")
         newWindow.attributes('-topmost','true')
        
   

	# sets the geometry of toplevel
    newWindow.geometry("300x250")
    newWindow.configure(background='light blue')
    newWindow.resizable(False,False)
    frm1=Frame(newWindow,bg="light blue")
    def addwork():
            srno=ent3.get()
            work=ent4.get()
   
            sql=("INSERT INTO workrequired(srno,work)"  "VALUES(%s,%s)" ) 
            cursor.execute(sql,(srno,work))
            mydb.commit()
            messagebox.showinfo("Confirmation","Work Added")
            print("DONE")
            return True
    cursor.execute('select count(*) from workrequired')
    next_num = cursor.fetchall()[0][0]
    frm1.pack(side=tk.LEFT,padx=20)

    var3=StringVar()
    srno=StringVar()
    var4=StringVar()
    workrequired=StringVar()
    label3=Label(frm1,textvariable=var3,bg="light blue")
    var3.set(" ")
    label3.grid(row=2,column=1,padx=10,pady=10)

    ent3=Entry(frm1,textvariable=srno,width=10)
    srno.set(next_num+1)
    ent3.grid(row=2,column=2,sticky=tk.W,padx=10,pady=10)
    label4=Label(frm1,textvariable=var4,bg="light blue")
    var4.set("Work Required")
    label4.grid(row=3,column=1,padx=10,pady=10)

    ent4=Entry(frm1,textvariable=workrequired)
    workrequired.set(" ")
    ent4.grid(row=3,column=2,padx=10,pady=10)

    def clear_text():
        workrequired.set(' ')
        cursor.execute('select count(*) from workrequired')
        next_num = cursor.fetchall()[0][0]
        srno.set(next_num+1)
    
   


    btn=Button(frm1, text="ADD",command= lambda:[addwork(), clear_text()])
    btn.grid(row=5,column=2,padx=10,pady=10)


	# A Label widget to show in toplevel
    Label(newWindow,
		text ="Add Work",bg="light blue").pack(padx=5, pady=20, side=tk.LEFT)



label = Label(root,
			text ="This is the main window")



btn = Button(root,
			text ="Add work",bg="light blue", height = 1, width = 7,
			command = openNewWindow).grid(row=2, column=2,sticky=tk.W)
def openNew():
    global new
    try:
        if new.state()=="normal":new.focus()
    except:
        new = Toplevel(root)
        new.title("Add Material")
        new.attributes('-topmost','true')
    
        
   
        
	# sets the geometry of toplevel
    new.geometry("300x250")
    new.configure(background='light blue')
    new.resizable(False,False)
    frm1=Frame(new,bg="light blue")
    def addmaterial():
        srno=ent5.get()
        material=ent6.get()
      
        sql=("INSERT INTO materials(srno,material)"  "VALUES(%s,%s)" ) 
        cursor.execute(sql,(srno,material))
        mydb.commit()
        messagebox.showinfo("Confirmation","Material Added")
        print("DONE")
        return True
    
    cursor.execute('select count(*) from materials')
    next_num = cursor.fetchall()[0][0]
    frm1.pack(side=tk.LEFT,padx=20)
    var5=StringVar()
    srno=StringVar()
    var6=StringVar()
    material=StringVar()
    label5=Label(frm1,textvariable=var5,bg="light blue")
    var5.set(" ")
    label5.grid(row=2,column=1,padx=10,pady=10)

    ent5=Entry(frm1,textvariable=srno,width=10)
    srno.set(next_num+1)
    ent5.grid(row=2,column=2,sticky=tk.W,padx=10,pady=10)

    label6=Label(frm1,textvariable=var6,bg="light blue")
    var6.set("material")
    label6.grid(row=3,column=1,padx=10,pady=10)

    ent6=Entry(frm1,textvariable=material)
    material.set(" ")
    ent6.grid(row=3,column=2,padx=10,pady=10)
    def clear_text():
        material.set(' ')
        cursor.execute('select count(*) from materials')
        next_num = cursor.fetchall()[0][0]
        srno.set(next_num+1)
    
   


    btn=Button(frm1, text="ADD",command= lambda:[addmaterial(), clear_text()])
    btn.grid(row=5,column=2,padx=10,pady=10)



btn = Button(root,
			text ="Add Material",bg="light blue", height = 1, width = 9,
			command = openNew).grid(row=4, column=2,sticky=tk.W)

#Text for our form
lab = Label(root, text=" Lab. Name",bg="light blue")
patientname=Label(root, text=" Patient.Name",bg="light blue")
patientage=Label(root, text="Patient Age",bg="light blue")
patientsex=Label(root,text="Sex",bg="light blue")
orderdate=Label(root, text="Order Date",bg="light blue")
date=Label(root,text=d,fg="black",bg="light blue",font=("Helvetica", 11))
reqdate=Label(root,text="Deliver By",bg="light blue")
work = Label(root, text="Work Required",bg="light blue")
toothnumber = Label(root, text="Tooth Number",bg="light blue")
material = Label(root, text="Material",bg="light blue")
shade = Label(root, text="Shade",bg="light blue")
incisal=Label(root,text="Incisal/occlusal 1/3rd",bg="light blue")
middle=Label(root,text="Middle 1/3rd",bg="light blue")
cervical=Label(root,text="Cervical 1/3rd",bg="light blue")
value=Label(root,text="Value",bg="light blue")
chroma=Label(root,text="Chroma",bg="light blue")
hue=Label(root,text="Hue",bg="light blue")
lessspace=Label(root,text=" In Case of inadequate occlussal clearance",font='Helvetica 18 bold', bg="light blue")

#Pack text for our form
lab.grid(row=1, column=0,padx=5,pady=5)
patientname.grid(row=1, column=2,padx=5,pady=5)
patientage.grid(row=2,column=2, padx=5,pady=5)
patientsex.grid(row=3,column=2,padx=5,pady=5)
orderdate.grid(row=4, column=2,padx=5,pady=5)
reqdate.grid(row=5, column=2,padx=5,pady=5)
date.grid(row=4,column=3,sticky=tk.W,padx=5,pady=5)
work.grid(row=2, column=0,padx=5,pady=5)
toothnumber.grid(row=3, column=0,padx=5,pady=5)
material.grid(row=4, column=0,padx=5,pady=5)
shade.grid(row=5, column=0,padx=5,pady=5)
incisal.grid(row=6,column=0,padx=5,pady=5)
middle.grid(row=7,column=0,padx=5,pady=5)
cervical.grid(row=8,column=0,padx=5,pady=5)
value.grid(row=6,column=1,padx=5,pady=5,sticky=tk.E)
chroma.grid(row=7,column=1,padx=5,pady=5,sticky=tk.E)
hue.grid(row=8,column=1,padx=5,pady=5,sticky=tk.E)
lessspace.grid(row=10,column=2)

# Tkinter variable for storing entries
labvalue = StringVar()
patientnamevalue = StringVar()
patientagevalue=StringVar()
patientsexvalue=StringVar()
orderdatevalue= StringVar()
reqdatevalue=StringVar()
workvalue = StringVar()
toothnumbervalue = StringVar()
materialvalue = StringVar()

incisalvalue=StringVar()
middlevalue=StringVar()
cervicalvalue=StringVar()
valuevalue=StringVar()
chromavalue=StringVar()
huevalue=StringVar()
labservicevalue = StringVar(value=" ")
toohreductionvalue=StringVar(value=" ")
reductioncopingvalue=StringVar(value=" ")
sendbackvalue=StringVar(value=" ")



#Entries for our form
labentry = ttk.Combobox(root,state="readonly",width=20,textvariable=labvalue)
labentry['values']=options
def caps(event):
  patientnamevalue.set(patientnamevalue.get().upper())

patientnameentry = Entry(root,width=23, textvariable=patientnamevalue)
patientnameentry.bind("<KeyRelease>", caps)
def validate_age(new_value):
   if len(new_value) == 0 or len(new_value) <= 2 and new_value.isdigit():
       return True
   else:
       return False
patientageentry = tk.Entry(root,width=7,textvariable=patientagevalue, validate="key", validatecommand=(root.register(validate_age), "%P"))
   

patientsexentry=ttk.Combobox(root,state="readonly",width=4,textvariable=patientsexvalue)
patientsexentry['values']=("M","F")
patientsexentry.current()
DateEntry=cal

workentry =ttk.Combobox(root,state="readonly",width=20,textvariable=workvalue)
workentry['values']=workr
workentry.current()

toothnumberentry =ttk.Combobox(root,state="readonly",width=20,textvariable=toothnumbervalue)
toothnumberentry['values']=("18","17","16","15","14","13","12","11","21","22","23","24","25","26","27","28","38","37","36","35","34","33","32","31","41","42","43","44","45","46","47","48")
toothnumberentry.current()
materialentry =ttk.Combobox(root,state="readonly",width=20,textvariable=materialvalue)
materialentry['values']=mater
materialentry.current()


incisalentry =ttk.Combobox(root,state="readonly",width=6,textvariable=incisalvalue)
incisalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
incisalentry.current()
middleentry =ttk.Combobox(root,state="readonly",width=6,textvariable=middlevalue)
middleentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
middleentry.current()
cervicalentry =ttk.Combobox(root,state="readonly",width=6,textvariable=cervicalvalue)
cervicalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
cervicalentry.current()
valuentry =ttk.Combobox(root,state="readonly",width=6,textvariable=valuevalue)
valuentry['values']=("0","1","2","3","4","5")
valuentry.current()
chromaentry =ttk.Combobox(root,state="readonly",width=6,textvariable=chromavalue)
chromaentry['values']=("L","M","R")
chromaentry.current()
hueentry =ttk.Combobox(root,state="readonly",width=6,textvariable=cervicalvalue)
hueentry['values']=("1","2","3")
hueentry.current()
# Packing the Entries
labentry.grid(row=1, column=1,padx=5,pady=5)
patientnameentry.grid(row=1, column=3,sticky=tk.W,padx=5,pady=5)
patientageentry.grid(row=2, column=3,sticky=tk.W,padx=5,pady=5)
patientsexentry.grid(row=3, column=3,sticky=tk.W,padx=5,pady=5)
DateEntry.grid(row=5,column=3,sticky=tk.W,padx=5,pady=5)
#orderdateentry.grid(row=2, column=7)
workentry.grid(row=2, column=1,padx=5,pady=5)
toothnumberentry.grid(row=3, column=1,padx=5,pady=5)
materialentry.grid(row=4, column=1,padx=5,pady=5)
#shadeentry.grid(row=5, column=3,padx=5,pady=5)
incisalentry.grid(row=6, column=1,sticky=tk.W,padx=5,pady=5)
middleentry.grid(row=7, column=1,sticky=tk.W,padx=5,pady=5)
cervicalentry.grid(row=8, column=1,sticky=tk.W,padx=5,pady=5)
valuentry.grid(row=6, column=2,sticky=tk.W,padx=5,pady=5)
chromaentry.grid(row=7, column=2,sticky=tk.W,padx=5,pady=5)
hueentry.grid(row=8, column=2,sticky=tk.W,padx=5,pady=5)

shadeguide=IntVar(value=1)

def vita():
    if shadeguide.get()== 2:
        incisalentry.configure(state="normal")
        middleentry.configure(state="normal")
        cervicalentry.configure(state="normal")
        valuentry.configure(state="disable")
        chromaentry.configure(state="disable")
        hueentry.configure(state="disable")
    else:
        incisalentry.configure(state="disable")
        middleentry.configure(state="disable")
        cervicalentry.configure(state="disable")
        valuentry.configure(state="normal")
        chromaentry.configure(state="normal")
        hueentry.configure(state="normal")
    






Radiobutton(root, text="Vita Classic",bg="light blue", variable=shadeguide, value=1, command=vita()).grid(row=5, column=1, sticky=W)
Radiobutton(root, text="Vita 3D",bg="light blue",variable=shadeguide, value=2, command=vita()).grid(row=5, column=2, sticky=W)


labservice = tk.Checkbutton(text="Want metal coping trial",bg="light blue", variable = labservicevalue,onvalue="Yes",offvalue="No")
labservice.grid(row=9, column=2,sticky=tk.W)
toohreduction = tk.Checkbutton(text="Do opposite tooth reduction",bg="light blue", variable = toohreductionvalue,onvalue="Yes",offvalue="No")
toohreduction.grid(row=11, column=2,sticky=tk.W)
reductioncoping = tk.Checkbutton(text="Make reduction coping",bg="light blue", variable = reductioncopingvalue,onvalue="Yes",offvalue="No")
reductioncoping.grid(row=12, column=2,sticky=tk.W)
sendback = tk.Checkbutton(text="Send the Case Back for correction",bg="light blue", variable = sendbackvalue,onvalue="Yes",offvalue="No")
sendback.grid(row=13, column=2,sticky=tk.W)


def clear_alltext():
    labvalue.set(' ')
    patientnamevalue .set(' ')
    patientagevalue.set(' ')
    patientsexvalue.set(' ')
    orderdatevalue.set(' ')
    reqdatevalue.set(' ')
    workvalue.set(' ')
    toothnumbervalue.set(' ')
    materialvalue.set(' ')
    #shadevalue = StringVar()
    incisalvalue.set(' ')
    middlevalue.set(' ')
    cervicalvalue.set(' ')
    labservicevalue.set(' ')
    toohreductionvalue.set(' ')
    reductioncopingvalue.set(' ')
    sendbackvalue.set(' ')



#Button & packing it and assigning it a command
btn3=Button(text=" submit ", command= lambda:[order(), clear_alltext()])
btn3.grid(row=15, column=2)



root.mainloop()
Reply
#2
Something like this?
#! /usr/bin/env python3

import tkinter as tk
from tkinter import ttk
from functools import partial

class Window:
    def __init__(self, root):
        self.box = ttk.Combobox(root)
        self.box['values'] = [1,2,3,4,5,6,7,8,9]
        self.box.current(0)
        self.box.pack()

        bt1 = tk.StringVar()
        self.chkbtn = ttk.Checkbutton(root, text='Enable')
        self.chkbtn.pack(side='left')
        self.chkbtn['variable'] = bt1
        self.chkbtn['onvalue'] = 'on'
        self.chkbtn['offvalue'] = 'off'
        self.chkbtn['command'] = partial(self.update, bt1)



    def update(self, var):
        btn = var.get()
        if btn == 'on':
            self.box.configure(state='disabled')
            self.chkbtn['text'] = 'Disable'
        else:
            self.box.configure(state='normal')
            self.chkbtn['text'] = 'Enable'



def main():
    root = tk.Tk()
    Window(root)
    root.mainloop()

main()

I mis-read the topic. Radio buttons should work the same.
With radiobuttons

#! /usr/bin/env python3

import tkinter as tk
from tkinter import ttk
from functools import partial

class Window:
    def __init__(self, root):
        self.box = ttk.Combobox(root)
        self.box['values'] = [1,2,3,4,5,6,7,8,9]
        self.box.current(0)
        self.box.pack()

        var = tk.StringVar()
        var.set(None)
        self.chkbtn = ttk.Radiobutton(root, text='Enable')
        self.chkbtn['variable'] = var
        self.chkbtn['value'] = 'enable'
        self.chkbtn['command'] = partial(self.update, var)
        self.chkbtn.pack(side='left')

        self.chkbtn2 = ttk.Radiobutton(root, text='Disable')
        self.chkbtn2['variable'] = var
        self.chkbtn2['value'] = 'disable'
        self.chkbtn2['command'] = partial(self.update, var)

        self.chkbtn2.pack(side='left')

    def update(self, var):
        var = var.get()
        if var == 'enable':
            self.box.configure(state='disabled')
        else:
            self.box.configure(state='normal')

def main():
    root = tk.Tk()
    Window(root)
    root.mainloop()

main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.

My Scripts
CookBook - Shmup - PyQt5 Music Player


Reply
#3
Next time you have a problem make a small example that demonstrates the problem. Usually this will expose the problem so you can solve it yourself. If it doesn't expose the problem at least you have a nice example to post. Here is my short example that demonstrates your problem.
import tkinter as tk
from tkinter import ttk

def vita():
    if shadeguide.get()== 2:
        incisalentry.configure(state="normal")
        valuentry.configure(state="disable")
    else:
        incisalentry.configure(state="disable")
        valuentry.configure(state="normal")

root = tk.Tk()

incisalentry = ttk.Combobox(root, state="readonly", width=6, values=("A1","A2"))
incisalentry.pack()

valuentry = ttk.Combobox(root, state="readonly", width=6, values=("0","1"))
valuentry.pack()

shadeguide = tk.IntVar(value=1)

tk.Radiobutton(root, text="Vita Classic", variable=shadeguide, value=1, command=vita()).pack()
tk.Radiobutton(root, text="Vita 3D", variable=shadeguide, value=2, command=vita()).pack()

root.mainloop()
As you say, changing the radio cluster does nothing. I wondered if I set up the radio buttons correctly. To test I added a print statement to vita().
ef vita():
    print(shadeguide.get())
    if shadeguide.get()== 2:
        incisalentry.configure(state="normal")
        valuentry.configure(state="disable")
    else:
        incisalentry.configure(state="disable")
        valuentry.configure(state="normal")
When I ran the program it immediately printed 1 twice, but did not print anything when I pressed either of the radio buttons.
Output:
1 1
So I am calling vita() twice when I create the window, but not when I press the button. Knowing this it is obvious what the problem is. See it?
tk.Radiobutton(root, text="Vita Classic", variable=shadeguide, value=1, command=vita())
tk.Radiobutton(root, text="Vita 3D", variable=shadeguide, value=2, command=vita())
Instead of binding the radio buttons to vita, I was calling vita() and binding the radio buttons to the return value (None). Removing the parenthesis fixes the problem.
tk.Radiobutton(root, text="Vita Classic", variable=shadeguide, value=1, command=vita).pack()
tk.Radiobutton(root, text="Vita 3D", variable=shadeguide, value=2, command=vita).pack()
vita()  # Call to initially enable/disable controls
This is what you should be doing whenever you encounter a problem. If you cannot see the source of the problem try adding a few print statements to verify that the code works as you expect. If the print statements don't uncover something (this time they did), make a simplified version of your program that still demonstrates the problem. This step nearly always exposes the problem because you have far less code to examine.

Now for the rant.

Your code is awful. I can see why you could not find the error because it is really hard to see what your code does. You have code that makes a window, then you define a function. That is followed by code that adds some widgets to the window and another function, I am going to call this the "stream of thought" design pattern. Whenever you think of anything to add to the program you add it to the bottom of the source file. Like stream of thought, this results in a tangled mess that is in need of editing.

The very first thing to do is delete this line.
from tkinter import *
Never, ever do import *. This imports every name (variables and functions) defined in tkinter. Do you know every variable in tkinter? Do you know every function? I you don't how do you know that your program isn't overriding some important tkinter function or redefining some important tkinter variable. After deleting this line you will have to sprinkle some "tk." here an there because your program will not know where to find "W" or "RadioButton". This small amount of pain will serve as a lesson, a lesson far less painful than the one you were doomed to face in the future when a tiny change to your code somehow ended up breaking everything.

Your next step should be to take all the functions and move them to the top of your file. When you move the files group them by functions that work together or functions that do the same kind of thing. Maybe openNew and openNewWindow should be grouped. And maybe they should have a better name. What is openWindow used for? What is openNewWindow used for? Why don't any of your functions have docstrings that say what they do? As you are organizing your functions you will add a docstring to each to describe what it does. And if the name of the function does not match the docstring description, you will rename the function.

The third step is to review your main code body and see if it contains anything else that should be a function. Do you have duplicate code? Maybe you need a function. A quick review shows a bunch of database queries. I would think about making these functions.

While doing this review I would also look at code like this:
incisalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
incisalentry.current()
middleentry =ttk.Combobox(root,state="readonly",width=6,textvariable=middlevalue)
middleentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
Why do you repeat that list? What do those combinations of letters and numbers mean? You use them in multiple places, so why not make a variable for that list and use the variable name.

It would almost make me think you don't like adding variables, but then you have code like this:
#Text for our form
lab = Label(root, text=" Lab. Name",bg="light blue")
patientname=Label(root, text=" Patient.Name",bg="light blue")
...
lab.grid(row=1, column=0,padx=5,pady=5)
patientname.grid(row=1, column=2,padx=5,pady=5)
patientname is a good variable name. I would probably want to use that to be the name of the patient. You waste it on a label. A variable that is only used once; to place the label in the grid. You don't need this variable. Make the label and place it in the grid in the same line. You don't need a variable for this label because you NEVER use that variable again. Sorry, that is wrong. You do use the variable again. Later on it is used for another label and again it is only used once: to place the label in the grid. Hey, wait. Is there duplicate code here?
Reply
#4
Thanks deanhystad. The problem solved and a big thanks for pointing out the shortcomings in the code and explaining them. I am a newbie just learning this is something I am doing as a hobby, hence the code is messy .I realized this when I saw other people's code . Thanks a lot for pointing out the short comings will try to organize it better.
Reply
#5
You might want to put your add work and add materials windows in their own files. Import these files just like you import other Python modules. I would write a class around these windows, but putting them in their own "module" offers much of the same benefits.

If you insist on using color you can do a lot better than setting the background color for every single widget. This talks about styles/themes to tkinter.

https://tkdocs.com/tutorial/styles.html
Reply
#6
will definitely look into it. Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to update the list of a combo box in a QTableView panoss 10 2,763 Feb-05-2022, 03:24 PM
Last Post: panoss
  [Tkinter] Radio Buttons Working Bassackwards gw1500se 6 1,310 Dec-07-2021, 07:13 PM
Last Post: menator01
  [Tkinter] Grid the radio buttons Joni_Engr 6 1,870 Nov-24-2021, 07:20 PM
Last Post: menator01
  problem with radio button crook79 3 1,785 Aug-12-2021, 02:30 PM
Last Post: deanhystad
  [Tkinter] binding versus disable DPaul 6 3,659 May-05-2021, 05:17 PM
Last Post: DPaul
  How to disable custom button Sancho_Pansa 7 1,874 Dec-04-2020, 02:21 PM
Last Post: buran
  [Tkinter] I can't get information from a radio button aquerci 2 1,953 May-20-2020, 10:31 AM
Last Post: aquerci
  How to disable focus on Frame in Tkinter? szafranji 1 2,113 May-13-2020, 10:45 PM
Last Post: DT2000
  Disable entry field and still see value scratchmyhead 5 2,608 May-11-2020, 08:09 PM
Last Post: menator01
  Referencing Combo Box MC2020 6 1,767 Feb-12-2020, 10:17 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020