Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inheritance problem
#1
def showHeader doesn't work and I realized that I did some mistake when I start coding the app. I created 'class application' with all elements from the main window, and 'def main()' for the main screen which does not inherite the class application, however it has Bar Menu top. I tried def main() to inheritate into class Application, but I had some errors.

What is the easiest way to fix this? I don't want to start from the begining, I worked many hours on this project :(

My final goal is to make this def to work:

def showHeader(self):
if showHeader.get() == 0:
self.top.pack()
elif showHeader.get() == 1:
self.top.pack_forget()


from class Application
# Top Frame
self.top = Frame(master, height = 50, bg = '#333')
self.top.pack(fill = X)


from def main()
# View
global showHeader
global showStatusbar

view = Menu(menubar, tearoff = 0)
view_under = Menu(view, tearoff = 0)
menubar.add_cascade(label = 'View', menu = view)
view.add_checkbutton(onvalue = 1, offvalue = 0, label = 'Show Header', variable = showHeader)
view.add_checkbutton(onvalue = 1, offvalue = 0, label = 'Show Status Bar', variable = showStatusbar)

showHeader = 1
showStatusbar = 1


class Application(object):
    

    def __init__(self, master):
        self.master = master
        


        ### Frames in the Main Window ###
        
        # Top Frame
        self.top = Frame(master, height = 50, bg = '#333')
        self.top.pack(fill = X)

        def Click(evt):
            clk = pwd.paswd()
        
        # Lock App
        self.lock_app = PhotoImage(file = 'img/lock.png')
        self.lock_app_lbl = Label(self.top, text = 'App Unlock ', fg = '#b3b3b3')
        self.lock_app_lbl.config(image = self.lock_app, compound = TOP, bg = '#333')
        self.lock_app_lbl.grid(row = 0, column = 4, sticky = E, ipadx = 410)
        self.lock_app_lbl.bind('<Button-1>', Click)

        

                
        # Middle Frame
        self.middle = Frame(master, height = 475, bg = '#121212')
        self.middle.pack(fill = BOTH)


        # Footer Frame
        self.footer = Frame(master, height = 50, bg = '#333')
        self.footer.pack(fill = X)
 
        # Header Image and Introduction Text

        # Image Logo
        self.top_image = PhotoImage(file = 'img/img_green.png')
        self.top_image_lbl = Label(self.top, image = self.top_image, bg = '#333')
        self.top_image_lbl.grid(row = 0, column = 0,padx = 15, pady = 15)

        # Header 1
        self.heading_text = Label(self.top, text = 'Application', fg = '#b3b3b3', bg = '#333', font = 'Helvetica')
        self.heading_text.grid(row = 0, column = 1)
        
        # Header 2
        self.heading_text = Label(self.top, text = 'Company Name', fg = '#b3b3b3', bg = '#333', font = 'Helvetica')
        self.heading_text.grid(row = 1, column = 1, sticky = E)

        # Employees Button
        self.emp_btn_img = PhotoImage(file = 'img/btn_my_employees.png')
        self.emp_btn = Button(self.middle, bd = 0, bg = '#121212', activebackground = '#121212', command = myEmployee)
        self.emp_btn.config(image = self.emp_btn_img, compound = LEFT)
        self.emp_btn.place(x = 80, y = 120)

        # Add Employee
        self.add_emp2_img = PhotoImage(file = 'img/btn_add_employee.png')
        self.add_emp2_btn = Button(self.middle, bd = 0, bg = '#121212', activebackground = '#121212', command = addEmp)
        self.add_emp2_btn.config(image = self.add_emp2_img)
        self.add_emp2_btn.place(x = 440, y = 120)

        # Clock-in
        self.clk_in_img = PhotoImage(file = 'img/btn_clock_in_out.png')
        self.clk_in = Button(self.middle, bd = 0, bg = '#121212', activebackground = '#121212')
        self.clk_in.config(image = self.clk_in_img, compound = LEFT, command = clkinout)
        self.clk_in.place(x = 440, y = 260)

        # Notes
        self.notes_img = PhotoImage(file = 'img/add_notes.png')
        self.notes = Button(self.middle, bd = 0, bg = '#121212', activebackground = '#121212')
        self.notes.config(image = self.notes_img, compound = LEFT, command = Notes)
        self.notes.place(x = 80, y = 260)


    def showHeader(self):
        if showHeader.get() == 0:
            self.top.pack()
        elif showHeader.get() == 1:
            self.top.pack_forget()  


class StatusBar(Label):
    def __init__(self):
        Label.__init(self)
        self.pack(side = BOTTOM)

# MAIN SCREEN #
def main():

    root = Tk()

    # Menu Bar
    menubar = Menu(root)
    root.config(menu = menubar)

    
    # View
    global showHeader
    global showStatusbar

    view = Menu(menubar, tearoff = 0)
    view_under = Menu(view, tearoff = 0)
    menubar.add_cascade(label = 'View', menu = view)
    view.add_checkbutton(onvalue = 1, offvalue = 0, label = 'Show Header', variable = showHeader)
    view.add_checkbutton(onvalue = 1, offvalue = 0, label = 'Show Status Bar', variable = showStatusbar)


    # General APP
    app = Application(root)
    root.title('Marianos')
    root.geometry('800x600+500+200')
    root.iconbitmap('w','img/icon.ico')
    root.resizable(False, False)
    root.mainloop()
    


if __name__ == '__main__':
    main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inheritance problem DPaul 18 5,397 May-07-2020, 10:13 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020