Python Forum

Full Version: Want somehelp with creating Gui with classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from tkinter import *
from tkinter import ttk


class App(Frame):
def __init__(self,*args,**kwargs):
Frame.__init__(self,*args,**kwargs)
self.grid(row=0,column=0)
self.master.title(string="Notebook Demo")
self.create_tabs()

def create_tabs(self):
panel = Frame(self,name="demo")
panel.grid(row=0,column=0)
nb = ttk.Notebook(panel,name="notebook")
tab1 = Area(nb)
tab2 = Volume(nb)
nb.add(tab1,text="Area")
nb.add(tab2,text="volume")
nb.grid(row=0,column=0)



class Area(Frame):
def __init__(self,*args,**kwargs):
elements = ['m', 'km', 'cm']
Frame.__init__(self,*args,**kwargs)
combobox1 = ttk.Combobox(state="readonly")
combobox1['values']= elements
combobox1.grid(row=1,column=1,padx=15,pady=15)
combobox1.current(0)
combobox2 = ttk.Combobox(state="readonly")
combobox2['values'] = elements
combobox2.grid(row=1, column=3, padx=15, pady=15)
combobox2.current(1)
label = ttk.Label(text='To')
label.grid(row=1,column=2)


class Volume(Frame):
def __init__(self,*args,**kwargs):
Frame.__init__(self,*args,**kwargs)
cube_elements = ['l', 'ml', 'Cubic meter']
combobox1 = ttk.Combobox(state="readonly")
combobox1['values'] = cube_elements
combobox1.grid(row=1, column=1, padx=15, pady=15)
combobox1.current(0)
combobox2 = ttk.Combobox(state="readonly")
combobox2['values'] = cube_elements
combobox2.grid(row=1, column=3, padx=15, pady=15)
combobox2.current(1)
label = ttk.Label(text='To')
label.grid(row=1, column=2)

i have a problem with this code i want to add these classes to notebook tabs but when add both of them are showing stuff of Volume class. tab1 should show the m,cm,km combobox but it is showing combobbox of volume. Help me
Please put code in code tags and fix indentation
see: https://python-forum.io/misc.php?action=help