This commit is contained in:
Nicole Weber 2021-10-20 15:21:48 +02:00
parent 19ec988d0a
commit 7fa199db64
3 changed files with 162 additions and 25 deletions

View File

@ -11,26 +11,96 @@ class View(Tk):
self.controller = c self.controller = c
self.title("Taktiles Spelling") self.title("Taktiles Spelling")
#self.resizable(height=False, width= False) #self.resizable(height=False, width= False)
self.geometry('{}x{}'.format(460,350)) self.geometry('500x400')
#self.configure(bg="blue") #self.configure(bg="blue")
topFrame = Frame(self, bg="white", height=10, width=450) #, padx=460, pady=10) self.createTopFrame()
l = Label(topFrame, text="Titel") self.createMainFrame()
b = Button(topFrame, text="test") self.createBottomFrame()
topFrame.pack()
l.grid(row=0, column=0)
b.grid(row=0, column=1)
testBtn = Button(self, text="test", command=lambda: self.controller.actionPerformed("test"))
testBtn.pack()
stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"))
stopBtn.pack()
self.protocol("WM_DELETE_WINDOW", self.onClosing) self.protocol("WM_DELETE_WINDOW", self.onClosing)
def createTopFrame(self):
self.topFrame = Frame(self, bg="blue", height=50, width=500) #, padx=460, pady=10)
l = Label(self.topFrame, text="taktilles Buchstabieren")
self.topFrame.grid(column=0, row=0)
self.topFrame.grid_propagate(0)
self.topFrame.pack_propagate(0)
l.pack()
def createMainFrame(self):
self.mainFrame = Frame(self, bg="red", height=250, width=500)
self.mainFrame.grid(column=0, row=1)
self.mainFrame.pack_propagate(0)
container = Frame(self.mainFrame, bg="cyan", height=250, width=500)
container.pack(side="top", fill="both", expand = True)
container.pack_propagate(0)
container.grid_propagate(0)
self.frames = {}
for F in (StartPage, WorkingPage):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.changeFrame("StartPage")
def changeFrame(self, pageName):
frame = self.frames[pageName]
frame.tkraise()
#testBtn = Button(self.mainFrame, text="test", command=lambda: self.controller.actionPerformed("test"), height=6, width = 10)
#testBtn.grid(row=0, column=0)
#stopBtn = Button(self.mainFrame, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=6, width = 10)
#stopBtn.grid(row=0, column=1)
def createBottomFrame(self):
self.bottomFrame = Frame(self, bg="green", height=250, width=500)
self.bottomFrame.grid(column=0, row=2)
self.bottomFrame.pack_propagate(0)
label = Label(self.bottomFrame, text="Hier stehen Infos")
label.pack()
def onClosing(self): def onClosing(self):
print("closing") print("closing")
self.destroy() self.destroy()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent, height=250, width=500, bg="red")
self.grid_propagate(0)
self.pack_propagate(0)
self.controller = controller
label = Label(self, text="This is the start page")
label.pack(side="top", fill="x", pady=10)
button1 = Button(self, text="Go to Page One",
command=lambda: controller.changeFrame("WorkingPage"))
button2 = Button(self, text="Go to Page Two",
command=lambda: controller.changeFrame("WorkingPage"))
button1.pack()
button2.pack()
class WorkingPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
label = Label(self, text="This is page 1")
label.pack(side="top", fill="x", pady=10)
button = Button(self, text="Go to the start page",
command=lambda: controller.changeFrame("StartPage"))
button.pack()

Binary file not shown.

View File

@ -1,17 +1,84 @@
try: try:
from Tkinter import * import tkinter as tk # python 3
from tkinter import font as tkfont # python 3
except ImportError: except ImportError:
from tkinter import * import Tkinter as tk # python 2
import tkFont as tkfont # python 2
def myClick(string): class SampleApp(tk.Tk):
myLabel = Label(root, text=string)
myLabel.pack()
root = Tk() def __init__(self, *args, **kwargs):
myButton = Button(root, text="Click me", command=lambda: myClick("test"), bg="blue") tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
myButton.pack() def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
root.mainloop() button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
button1.pack()
button2.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()