Working with Python, Unhiding a frame depending on numeric value in textbox

bruce.hagen

I have a Py file that consists of 100+ frames, aprox 80+ radio buttons and 65 textboxes. I have attached shortened exert from main file. Textbox 1 takes on a value when a radio button is pressed. When button "Show Values is pressed it inserts the accumulated of all textboxes and places that value in Textbox 2. When final radio button is pressed it should unhide frame 5.
My problem is with deff onclick 5
I am close to my final stage of this file.
Any help would be appreciated

42 Views
About the Author
from tkinter import *
from tkinter import Tk
import tkinter as tk
from tkinter import ttk
root=tk.Tk()
root.title("Dental Milling Machines")
root.geometry("1000x900")
      

      

def onclick5():
   if ([textbox2], [">0" and "<10.1"]):
      frame5.grid(row=0, column=2, pady=2,sticky="NW")
   else:
      frame5.grid_forget()
      
 
def onclick1():
    textbox1.delete('1.0', 'end')
    textbox1.insert('end', '2.83')

def onclick2():
    textbox1.delete('1.0', 'end')
    textbox1.insert('end', '5.66')

def onclick3():
    textbox1.delete('1.0', 'end')
    textbox1.insert('end', '8.49')

def to_float( string ):
    try: 
        return float( string )
    except ValueError:
        return 0.0
    
def onclick4():
    tot = 0.0
    for box in text_boxes_to_sum:
        v = box.get( '1.0', 'end' )
        tot += to_float( v )
    textbox2.delete( '1.0', 'end' )
    textbox2.insert( 'end', str(tot) )
    
      
    



button_var1 = tk.IntVar()
button_var2 = tk.IntVar()

frame1 = Frame(root, height = 150, width= 150, relief= RAISED, bd=8, bg="blue")
frame2 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=8, bg="lightblue")
frame3 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=8, bg="lightblue")
frame4 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=8, bg="lightblue")
frame5 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=8, bg="lightblue")
frame6 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=8, bg="lightblue")

textbox1 = Text(frame2, borderwidth=1, wrap="none", width=10, height=2)
textbox1.grid(row=5, column=0, sticky="w")
textbox2 = Text(frame3, borderwidth=1, wrap="none", width=10, height=1)
textbox2.grid(row=1, column=0, sticky="NESW")
textbox3 = Text(frame5, borderwidth=1, wrap="none", width=10, height=1)
textbox3.grid(row=0, column=0, sticky="NESW")
text_boxes_to_sum = [ textbox1 ]  


frame1.grid(row=0, column=0, pady=2,sticky="NW")
frame2.grid(row=1, column=0, pady=2,sticky="NW")
label = Label(frame2, text="Select # Of Units Being Used", fg="red")
label.grid(row=0, column=0, pady= 1, padx=1, sticky= "W")

frame3.grid(row=2, column=0, pady=2,sticky="NW")
label = Label(frame3, text="Total CFM Values", fg="red")
label.grid(row=0, column=0, pady= 1, padx=1, sticky= "W")

frame4 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=0, bg="lightyellow")
frame4.grid(row=8, column=0, pady=2,padx=3, sticky="E")

frame5 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=0, bg="lightyellow")
label = Label(frame5, text="Reccommended Compressor Package", fg="red")
label.grid(row=0, column=0, pady= 1, padx=1, sticky= "W")
label = Label(frame5, text="Compressor Package 1", fg="black")
label.grid(row=2, column=0, pady= 10, padx=5, sticky= "EW")

frame6 = Frame(frame1, height = 150, width= 150, relief= RAISED, bd=0, bg="lightyellow")
label = Label(frame6, text="Reccommended Compressor Package", fg="red")
label.grid(row=0, column=0, pady= 1, padx=1, sticky= "W")
label = Label(frame6, text="Compressor Package 2", fg="black")
label.grid(row=2, column=0, pady= 10, padx=5, sticky= "EW")


button1=Radiobutton(frame2, text="1 Unit ", variable=button_var1, command=onclick1)
button1.grid(row=1, column=0, pady= 1, padx= 5, sticky= "W")
button2=Radiobutton(frame2, text="2 Units ", variable=button_var1, command=onclick2)
button2.grid(row=2, column=0, pady= 1, padx= 5, sticky= "W")
button3=Radiobutton(frame2, text="3 Units ", variable=button_var1, command=onclick3)
button3.grid(row=3, column=0, pady= 1, padx= 5, sticky= "W")
button4=Radiobutton(frame3, text="Show Values ", variable=button_var1, command=onclick4, value = 0 )
button4.grid(row=3, column=0, pady= 1, padx= 5, sticky= "W")

button5=Radiobutton(frame4, text="Show Reccommended Compressor Package ", variable=button_var2, command=onclick5)
button5.grid(row=0, column=0, pady= 1, padx= 5, sticky= "W")


root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.