Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6216417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:14:48+00:00 2026-05-24T07:14:48+00:00

I am writing a GUI Python application. I am using Tkinter + PythonMegaWidgets for

  • 0

I am writing a GUI Python application.
I am using Tkinter + PythonMegaWidgets for semplicity reasons.

Going straight to the point, I need to extend Tkinter.Frame baseclass, by adding some custom member functions which provides extra-functionalities.

These “Custom Frames” will be added to single tabs of a Pmw.NoteBook object.

Official related docs can be found at: http://pmw.sourceforge.net/doc/NoteBook.html

Later, I need to retrieve “Custom Frame” instances from NoteBook, invoking custom member functions that I have added; here the problems begins…

despite the principle of Duck Typing, I can not access ANY of these “extra-methods” because the methods of Pmw.NoteBook class can only return Frame objects!.

I can not find any solution.

Below a piece of sample (more simplified) code which describes in detail my issue.

from Tkinter import *
from Pmw import NoteBook

# I define a custom frame, by extending Tkinter.Frame baseclass

class CustomPanel(Frame):
    def __init__(self, master, _text):
        Frame.__init__(self, master)
        self.label = Label(self, text=_text) 
        self.localVariable = "Hello, world!" # I define a new local variable
        self.label.pack()
        self.pack()

    # I define a custom member function, which I _ABSOLUTELY_ want to be accessible.

    def customMethod(self):
        print self.localVariable

# main frame of application

class MyFrame(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.noteBook = NoteBook(self) # I create a NoteBook object...

        tab1 = self.noteBook.add("tab 1") # then, I add one (empty) tabs to it

        panel1 = CustomPanel(tab1, "hello")

        self.button = Button(self, text="Call CustomMethod()!", command=self.callCustomMethod) # I add a button test

        self.noteBook.grid()
        self.button.grid(row=1)
        self.pack()
        self.mainloop()

    # I define click handler for button, 

    def callCustomMethod(self):
        panel1 = self.noteBook.page(0) # I try to get frame contained in current tab

        # pane11 is supposed to be a 'CustomPanel' object; 

        try:
            panel1.customMethod() # ...then, custom method should be accessible

        except AttributeError:
            print 'AttributeError!'

        # for illustration purpose only, I show that Panel1 is a 'Frame'(superclass) object only!
        print panel1.__class__

frame = MyFrame() # create a MyFrame instance

Pressing the button, console output is:

AttributeError!
Tkinter.Frame

to anticipate objections:

1- Set panel1.class attribute, as showed below,

    try:
        panel1.__class__ = CustomPanel
        panel1.customMethod() # ...then, custom method should be accessible

    except AttributeError:
        print 'AttributeError!'

DON’T work, because customMethod() could not access in any case to localVariable, which is declared in CustomPanel subclass only;

2- I can not even recall CustomPanel constructor, because this will RESET original member variables, which I want to retrieve with their original values.

Any help is appreciated.

IT

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:14:49+00:00Added an answer on May 24, 2026 at 7:14 am

    I don’t think you need to change the class of the notebook tab, you can just add your custom frame inside that tab. Just tell the frame what your inner frame is, and remember to pack your inner frame inside the tab frame.

    For example:

    class MyFrame(Frame):
        def __init__(self, master=None):
            ...
            panel1 = CustomPanel(tab1, "hello")
            panel1.pack(fill="both", expand=True)
            tab1.inner_panel = panel1
            ...
    
        def callCustomMethod(self):
            tab1 = self.noteBook.page(0) 
            panel1 = tab1.inner_panel
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application in Python using Tkinter to manage my GUI. There
I'm writing a GUI application in Python using wxPython and I want to display
I'm writing a python application that has a glade gui. Using subprocess to execute
I've been writing a long GUI in Python using Tkinter. One thing that I
I'm writing a GUI for an application using Swing, and in the interests of
I am writing a GUI application using Django 1.1.1. This is the views.py: from
I'm writing a Python program with a GUI built with the Tkinter module. I'm
I am new to Python. I am writing an application using wxPython and I
I'm currently writing a program in python with a gui using wxpython. The program
I am writing a simple Python script with no GUI. I want to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.