As the title suggests I have a very basic Tkinter application with the functionality of allowing the user to choose one of three options via radio buttons:
import tkinter as tk
from tkinter import *
from mass_estimator import mass_estimator
from gc_plot import gc_plot()
from seq_conversion import seq_conversion
window = tk.Tk()
window.title('Sequence Manipulator')
title = tk.Label(window, text='DNA Sequence Manipulator')
title.pack()
frame = Frame(window)
module = StringVar()
radio_1 = Radiobutton(frame, text='Sequence Converter',
variable=module, value='DNA Sequence Converter')
radio_2 = Radiobutton(frame, text='GC Plot',
variable=module, value='DNA Sequence GC Content Plotter')
radio_3 = Radiobutton(frame, text='Mass Est.',
variable=module, value='Sequence Molecular Mass Estimator')
def selected():
if module.get() == 'Sequence Molecular Mass Estimator':
mass_estimator()
elif module.get() == 'DNA Sequence GC Content Plotter':
gc_plot()
elif module.get() == 'DNA Sequence Converter':
seq_conversion()
btn = Button(frame, text='Choose', command=selected())
btn.pack(side=RIGHT, padx=5)
radio_1.pack(side=LEFT)
radio_2.pack(side=LEFT)
radio_3.pack(side=LEFT)
frame.pack(padx=30, pady=30)
window.mainloop()
the intended function of this code is to call the relevant function depending on which radio button is selected. As of now the functions only include print statements to ensure the function is being called correctly, however they are not. I was just wondering if anyone could suggest how I could change my code so that selecting a radio button will call the corresponding function. Thanks!