I have been trying to make a class based on Tk(). My code is such a mess, I would be embaressed to show you what I came up with. Here is what I am trying to do

class Window(Tk):
    fill in the code
win = Window()

I can do this with out using classes, but as a single object I am having trouble
I would like the window to be a certain dimension, and have a single button in it. I would greatly appreciate an example.

Recommended Answers

All 3 Replies

Hi Shanenin,

Try this:

from Tkinter import *
# -- The application class
class TkBasic:
     # -- Initializes new instances of TkBasic
     def __init__(self, root):
          # Change the window geometry
          # Add the window Frame to which all widgets will be bound
          self.mainframe = Frame(root)
          # Add a Button widget (when clicked, it closes the app)
          self.button = Button(self.mainframe, text="Close",
     # -- Closes the application
     def close(self):
# -- The following code executes upon command-line invocation
root = Tk()
tkb = TkBasic(root)

To learn about geometry strings, go here. To learn more about making your apps look decent (layout management), go here. To learn more about Buttons and other widgets, try here.

Thank you. That will give me some ideas, you seem to do it alot differently then I was trying.

Thanks G-Do for your excellent sample code and the references. Good sample code seems to be missing with most common Python tutorials.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.