I'm trying to make a small tkinter program to calculate the area of shapes and volumes and I've made a main py file "area_volume_calculator.py" and two libraries "area.py" and "volume.py"
The main program's radio buttons work fine, but when I create the second window from Area_calculator
I can't seem to get radio buttons to work properly. When it opens, the last 2 radio buttons are selected already.
I can still select an option but self.choice.get() always returns the default value which is -1, I don't know how to get it to work.
Can anyone help me get the radio buttons to work properly? Any and all help is appreciated
Main Program:
from tkinter import *
from area import *
# from volume import *
class Menu:
def __init__(self):
self.window = Tk()
self.window.title("Areas and Volumes")
# self.name_label = Label(self.window, text = "Name: ")
# self.name_label.grid(row=0,column=0)
# self.name_entry = Entry(self.window)
# self.name_entry.grid(row=0,column=1)
# self.age_label = Label(self.window, text = "Age: ")
# self.age_label.grid(row=1,column=0)
# self.age_entry = Entry(self.window)
# self.age_entry.grid(row=1,column=1)
self.choice = IntVar()
self.area_radiobutton = Radiobutton(self.window, text = "Area Calculator", var = self.choice, value = 0)
self.area_radiobutton.grid(row=2,column=0)
self.volume_radiobutton = Radiobutton(self.window, text = "Volume Calculator", var = self.choice, value = 1)
self.volume_radiobutton.grid(row=3,column=0)
self.choice.set(-1)
self.submit_button = Button(self.window, text = "Submit", command = self.submit)
self.submit_button.grid(row=4,column=0)
print(self.choice.get())
self.window.mainloop()
def submit(self):
print(self.choice.get())
if self.choice.get() == 0:
area_calculator = Area_calculator()
# elif self.choice.get() == 1:
# volume_calculator = Volume_calculator()
menu = Menu()
area.py library:
from tkinter import *
class Area_calculator():
def __init__(self):
self.window = Tk()
self.window.title
self.window.title("Area Calculator")
self.choice_label = Label(self.window, text = "Choose a shape")
self.choice_label.grid(row=0,columnspan=1)
self.choice = IntVar()
self.rectangle_radiobutton = Radiobutton(self.window, text = "Rectangle", var = self.choice, value = 0)
self.rectangle_radiobutton.grid(row=1,column=0)
self.triangle_radiobutton = Radiobutton(self.window, text = "Triangle", var = self.choice, value = 1)
self.triangle_radiobutton.grid(row=2,column=0)
self.circle_radiobutton = Radiobutton(self.window, text = "Circle", var = self.choice, value = 2)
self.circle_radiobutton.grid(row=3,column=0)
self.submit_button = Button(self.window, text = "Submit", command = self.submit)
self.submit_button.grid(row=4,column=0)
self.choice.set(-1)
print(self.choice.get())
self.window.mainloop()
def submit(self):
print(self.choice.get())
# if self.choice.get() == 0:
# rectangle_calculator = Rectangle_calculator()
# elif self.choice.get() == 1:
# triangle_calculator = Triangle_calculator()
# elif self.choice.get() == 2:
# circle_calculator = Circle_calculator()