You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIViewTKinter.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. try:
  2. from Tkinter import *
  3. except ImportError:
  4. from tkinter import *
  5. from UIController import *
  6. class View(Tk):
  7. def __init__(self, c, *args, **kwargs):
  8. Tk.__init__(self, *args, **kwargs)
  9. self.controller = c
  10. self.title("Taktiles Spelling")
  11. self.h = 400
  12. self.w = 500
  13. self.faktor = [(0.125),(0.625), (0.25)]
  14. #self.resizable(height=False, width= False)
  15. self.geometry('{}x{}'.format(self.w,self.h))
  16. self.createTopFrame()
  17. self.createMainFrame()
  18. self.createBottomFrame()
  19. self.bind("<Configure>", self.adjustSize)
  20. self.protocol("WM_DELETE_WINDOW", self.onClosing)
  21. def changeFrame(self, pageName):
  22. frame = self.frames[pageName]
  23. frame.tkraise()
  24. def adjustSize(self, event):
  25. if(str(event.widget) =="."):
  26. self.h = event.height
  27. self.w = event.width
  28. self.topFrame.configure(height=(self.h*self.faktor[0]), width=self.w)
  29. self.mainFrame.configure(height=(self.h*self.faktor[1]), width=self.w)
  30. self.bottomFrame.configure(height=(self.h*self.faktor[2]), width=self.w)
  31. self.container.configure(height=(self.h*self.faktor[1]), width=self.w)
  32. for f in self.frames:
  33. self.frames[f].configure(height=(self.h*self.faktor[1]), width=self.w)
  34. def onClosing(self):
  35. print("closing")
  36. self.destroy()
  37. def createTopFrame(self):
  38. self.topFrame = Frame(self, bg="blue", height=50, width=500) #, padx=460, pady=10)
  39. self.toplabel = Label(self.topFrame, text="taktilles Buchstabieren")
  40. self.topFrame.columnconfigure(0, weight=1) # Set weight to row and
  41. self.topFrame.rowconfigure(0, weight=1) # column where the widget is
  42. self.topFrame.grid(column=0, row=0)
  43. self.topFrame.grid_propagate(0)
  44. self.topFrame.pack_propagate(0)
  45. self.toplabel.grid()
  46. def createMainFrame(self):
  47. self.mainFrame = Frame(self, bg="red", height=250, width=500)
  48. self.mainFrame.grid(column=0, row=1)
  49. self.mainFrame.pack_propagate(0)
  50. self.container = Frame(self.mainFrame, bg="cyan", height=250, width=500)
  51. self.container.pack(side="top", fill="both", expand = True)
  52. self.container.pack_propagate(0)
  53. self.container.grid_propagate(0)
  54. self.frames = {}
  55. for F in (StartPage, WorkingPage):
  56. page_name = F.__name__
  57. frame = F(parent=self.container, controller=self.controller)
  58. self.frames[page_name] = frame
  59. frame.grid(row=0, column=0, sticky="nsew")
  60. self.changeFrame("StartPage")
  61. def createBottomFrame(self):
  62. self.bottomFrame = Frame(self, bg="green", height=100, width=500)
  63. self.bottomFrame.grid(column=0, row=2)
  64. self.bottomFrame.pack_propagate(0)
  65. self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos")
  66. self.bottomlabel.pack()
  67. def setInfoText(self, text):
  68. self.bottomlabel['text'] = text
  69. def setTitleText(self,text):
  70. self.toplabel['text'] = text
  71. class StartPage(Frame):
  72. def __init__(self, parent, controller):
  73. Frame.__init__(self, parent, height=250, width=500, bg="red")
  74. self.grid_propagate(0)
  75. self.pack_propagate(0)
  76. self.controller = controller
  77. testBtn = Button(self, text="test", command=lambda: self.controller.actionPerformed("test"), height=6, width = 10)
  78. testBtn.grid(row=0, column=0)
  79. freeSpellingBtn = Button(self, text="freeSpelling", command=lambda: self.controller.actionPerformed("freeSpelling"), height=6, width = 10)
  80. freeSpellingBtn.grid(row=0, column=1)
  81. class WorkingPage(Frame):
  82. def __init__(self, parent, controller):
  83. Frame.__init__(self, parent)
  84. self.controller = controller
  85. stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=6, width = 10)
  86. stopBtn.pack()