SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 11th, 2004, 09:41 PM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
Question How to Clear A Tkinter Screen.

What I need to know is how to clear a Tkinter Window. I need the last screen to clear after the user clicks next then have new questions appear on that cleared screen.

Thanks,
Nick125

Reply With Quote
  #2  
Old April 12th, 2004, 12:19 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
I would set up your various screens in separate frames, then call the grid() and grid_forget() methods to show/hide the frames as you need. grid_forget() does basically the opposite of grid(), removing the frame from the screen but not destroying it (ie it can be shown again with another grid() call on the widget).

Reply With Quote
  #3  
Old April 12th, 2004, 12:26 AM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
How would you do that? I am new to Python and programming. If you can, provide a small example.

Thanks,
Nick125

Reply With Quote
  #4  
Old April 12th, 2004, 07:01 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
ok, here's a quick example. you just need to note that I've stored all the pages of the application in a list to iterate over, and that all the work is done 'next' method of the Application class. if you have any queries on the window components used or anything else Tkinter related, this site will come in handy.

here's the code:

Code:
from Tkinter import *

class Page(Frame):
    """Page is the Frame that will be added/removed at will"""
    def __init__(self, root, id):
        Frame.__init__(self, root)
        Label(self, text="Frame %d" % id).pack()

class Application(Frame):
    """Main application where everything is done"""
    def __init__(self, root):
        Frame.__init__(self, root)
        self.root = root
        self.page = 0
        self.pages = [Page(self, x) for x in range(5)]#creates list of 5 pages
        self.pages[self.page].pack(side=TOP)
        Button(self, text="Next", command=self.next).pack(side=BOTTOM)

    def next(self):
        """changes the current page. I've only done next here, but you could
        do backwards, skip pages, etc"""
        self.pages[self.page].pack_forget() #remove the current page
        self.page += 1
        if self.page >= 5: #checking haven't gone past the end of self.page
            self.page = 0
        self.pages[self.page].pack(side=TOP) #add the next one
        
if __name__ == "__main__":
    root = Tk()
    app = Application(root)
    app.pack()
    root.mainloop()


any other questions/queries/etc, don't hesitate to ask.

Reply With Quote
  #5  
Old April 12th, 2004, 04:33 PM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
Ok what I need is a menu system that goes to another page then another with other information. How would you create something like that. What I really need to know is how to define the pages that are used in the program.

Thanks,
Nick125

Reply With Quote
  #6  
Old April 12th, 2004, 08:52 PM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
as I said in my original post, just use a Frame object to represent each page. my code above does almost exactly what you want (from what I can tell), except it just puts a simple Label on each page. You'll have to create a more advanced interface obviously, with more text/widgets/etc. with my code above, you could do that by modifying the Page class to contain whatever you need. if you keep the same page layout for all pages, just with a different blurb of information on each, you could keep the Page class as a generic framework and keep the different pieces of text in a list. not sure if I'm making sense, so here's another example:

Code:
from Tkinter import *

class Page(Frame):
    def __init__(self, root, id):
        Frame.__init__(self, root)
        pages = ["This is the info on page 0",
                 "This is the info on page 1",
                 "This is the info on page 2",
                 "This is the info on page 3",
                 "This is the info on page 4"]
        Label(self, text=pages[id]).pack(fill=BOTH)

class Application(Frame):
    """Main application where everything is done"""
    def __init__(self, root):
        Frame.__init__(self, root)
        self.root = root
        self.page = 0
        self.pages = [Page(self, x) for x in range(5)]#creates list of 5 pages
        self.pages[self.page].grid(row=0, column=0, columnspan=2)
        Button(self, text="Next", command=self.next).grid(row=1, column=1)
        Button(self, text="Back", command=self.back).grid(row=1, column=0)

    def next(self):
        """changes the current page. I've only done next here, but you could
        do backwards, skip pages, etc"""
        self.pages[self.page].grid_forget() #remove the current page
        self.page += 1
        if self.page >= 5: #checking haven't gone past the end of self.page
            self.page = 4
        self.pages[self.page].grid(row=0, column=0, columnspan=2)
        
    def back(self):
        self.pages[self.page].grid_forget()
        self.page -= 1
        if self.page < 0:
            self.page = 0
        self.pages[self.page].grid(row=0, column=0, columnspan=2)
        
if __name__ == "__main__":
    root = Tk()
    app = Application(root)
    app.pack()
    root.mainloop()


from there you should be able to work with it easily. just put the real text in, some buttons to finish/close and whatever else, help etc.

Reply With Quote
  #7  
Old April 13th, 2004, 03:10 AM
Nick125 Nick125 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Albuquerque, New Mexico
Posts: 137 Nick125 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 1 m 38 sec
Reputation Power: 5
Send a message via AIM to Nick125
How would I create the different windows with radio buttons, text, fields that are totally different in the pages list. I am new to this and still don't understand some of Tkinter.

Thanks,
Nick125

Reply With Quote
  #8  
Old April 13th, 2004, 04:10 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
doing that would mean you couldn't use the very generic approach to the task as I did above. you would need to create different Page classes for each separate page, or atleast each one that is unique in terms of widgets/layout.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > How to Clear A Tkinter Screen.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway