Уведомления

Группа в Telegram: @pythonsu

#1 Фев. 17, 2010 07:47:12

Cover Story
От:
Зарегистрирован: 2008-08-26
Сообщения: 192
Репутация: +  0  -
Профиль   Отправить e-mail  

Смена фреймов в Tkinter

Вот еще один пример смены фреймов

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()



Python 2.7.3
Pyside 1.1.2

Офлайн

#2 Фев. 18, 2010 19:54:24

rokki
От:
Зарегистрирован: 2009-09-22
Сообщения: 79
Репутация: +  0  -
Профиль   Отправить e-mail  

Смена фреймов в Tkinter

Cover Story
Вот еще один пример смены фреймов
спасибо, я как раз именно этот пример и использовал как пример, нашел его в интернете на каком то зарубежном форуме.вот что значит интернет тесен!



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version