Python Forum
[Tkinter] Can´t create a class for frames
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Can´t create a class for frames
#1
Bug 
Hi Guys,

I need your help Angel


This Stuff is working well:
import tkinter as tk
from tkinter import *
from tkinter import ttk, filedialog

## window
    win = Tk()  # Create an instance of tkinter frame
    win.title('       F04    universal GUI     ') #set title of window
    myscreenwidth= win.winfo_screenwidth() #get screenwidth
    myscreenheight= win.winfo_screenheight() #get screenheight
    win.geometry("%dx%d+0+0" %(myscreenwidth,myscreenheight)) #set window size to full screen[b][/b]
But now i want to create a new class for my frames ( -> same attributes (like background color) for all instances), which does not really work:

#define a notebook
    notebook1=ttk.Notebook(win) #initialise
    notebook1.pack(fill="both", expand=1) #most simple placement for only 1 object



    class CustomFrames(tk.Frame): 
        def __init__(self,notebook1):
            super().__init__(notebook1)
            super().notebook1.add(self.frame, text="Start   ")            
    
frame01Start=CustomFrames(notebook1) #create instance
Error:
super().notebook1.add(self.frame, text="Start ") AttributeError: 'super' object has no attribute 'notebook1'
Any ideas whats wrong here?





I also found out that this (below) works well, but i find it not an elegant style to create an object "Frame01.frame" , and also I would like to understand the issue about my original code...
    class CustomFrames:
        def __init__(self):
            self.frame=tk.Frame(notebook1)
Thank you for your help! Shy
Reply


Messages In This Thread
Can´t create a class for frames - by ThomasFab - Sep-27-2022, 12:30 PM
RE: Can´t create a class for frames - by ThomasFab - Sep-27-2022, 01:50 PM
RE: Can´t create a class for frames - by ThomasFab - Sep-28-2022, 05:46 AM
RE: Can´t create a class for frames - by ThomasFab - Sep-28-2022, 09:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Class function does not create command button Heyjoe 2 2,343 Aug-22-2020, 08:06 PM
Last Post: Heyjoe
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 11,087 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

User Panel Messages

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