Nicole Weber 3 years ago
parent
commit
7fa199db64
3 changed files with 159 additions and 22 deletions
  1. 82
    12
      Masterarbeit/UIViewTKinter.py
  2. BIN
      Masterarbeit/UIViewTKinter.pyc
  3. 77
    10
      Masterarbeit/test.py

+ 82
- 12
Masterarbeit/UIViewTKinter.py View File

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)
l = Label(topFrame, text="Titel")
b = Button(topFrame, text="test")
self.createTopFrame()
self.createMainFrame()
self.createBottomFrame()


topFrame.pack()
l.grid(row=0, column=0)
b.grid(row=0, column=1)
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")


testBtn = Button(self, text="test", command=lambda: self.controller.actionPerformed("test"))
testBtn.pack()
self.topFrame.grid(column=0, row=0)
self.topFrame.grid_propagate(0)
self.topFrame.pack_propagate(0)
l.pack()


stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"))
stopBtn.pack()
def createMainFrame(self):


self.protocol("WM_DELETE_WINDOW", self.onClosing)
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()

BIN
Masterarbeit/UIViewTKinter.pyc View File


+ 77
- 10
Masterarbeit/test.py View File

try:
from Tkinter import *
try:
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):
myLabel = Label(root, text=string)
myLabel.pack()
class SampleApp(tk.Tk):


root = Tk()
myButton = Button(root, text="Click me", command=lambda: myClick("test"), bg="blue")
def __init__(self, *args, **kwargs):
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)


myButton.pack()
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame


root.mainloop()
# 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):

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)

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

Loading…
Cancel
Save