this is a follow-up from a previous question that I had posted before. The issue that I am facing is that, my pop-up menu is able to allow me to select the value that I want, however I am not able to read and use the value for subsequent processing outside the 2 Classes - App and TestFrame. As I am relatively new to Tkinter functions, I would greatly appreciate any form of help/advice on how I can read and use the values for further processing, outside the Class functions.
Thank you!
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("800x400")
self.title('ABC')
for r in range(5):
self.rowconfigure(r, weight=1)
for c in range(8):
self.columnconfigure(c, weight=1)
self.testFrame1 = TestFrame()
self.testFrame1.grid(row=0, column=0, rowspan=3, columnspan=3, sticky='nsew')
class TestFrame(tk.Frame):
def __init__(self):
super().__init__()
self.dimension = ('106','108','110','112','114','126','128','130','132','134','136','138','140','146','148','150','152','154','360','380','400','420','440','500', '520', '540',
'560', '580', '600','780','800','820')
self.option_var =tk.IntVar()
paddings = {'padx': 5, 'pady': 5}
label = ttk.Label(self, text='Select the dimension for DOB:').grid(column=0, row=0, sticky=tk.W, **paddings)
#DOB
option_menu = ttk.OptionMenu(
self,
self.option_var,
self.dimension[0],
*self.dimension,
command=self.option_changed)
option_menu.grid(column=1, row=0, sticky=tk.W, **paddings)
self.output_label = ttk.Label(self, foreground='red')
self.output_label.grid(column=0, row=1, sticky=tk.W, **paddings)
def option_changed(self, *args):
self.output_label['text'] = f'You selected: {self.option_var.get()}'
App().mainloop()