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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. self.frames[f].adjustSize(height=(self.h*self.faktor[1]), width=self.w/2)
  35. def onClosing(self):
  36. print("closing")
  37. self.destroy()
  38. def createTopFrame(self):
  39. self.topFrame = Frame(self, bg="blue", height=50, width=500) #, padx=460, pady=10)
  40. self.toplabel = Label(self.topFrame, text="taktilles Buchstabieren")
  41. self.topFrame.columnconfigure(0, weight=1) # Set weight to row and
  42. self.topFrame.rowconfigure(0, weight=1) # column where the widget is
  43. self.topFrame.grid(column=0, row=0)
  44. self.topFrame.grid_propagate(0)
  45. self.topFrame.pack_propagate(0)
  46. self.toplabel.grid()
  47. def createMainFrame(self):
  48. self.mainFrame = Frame(self, bg="red", height=250, width=500)
  49. self.mainFrame.grid(column=0, row=1)
  50. self.mainFrame.pack_propagate(0)
  51. self.container = Frame(self.mainFrame, bg="cyan", height=250, width=500)
  52. self.container.pack(side="top", fill="both", expand = True)
  53. self.container.pack_propagate(0)
  54. self.container.grid_propagate(0)
  55. self.frames = {}
  56. for F in (StartPage, WorkingPage):
  57. page_name = F.__name__
  58. frame = F(parent=self.container, controller=self.controller)
  59. self.frames[page_name] = frame
  60. frame.grid(row=0, column=0, sticky="nsew")
  61. self.changeFrame("StartPage")
  62. def createBottomFrame(self):
  63. self.bottomFrame = Frame(self, bg="green", height=100, width=500)
  64. self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos\nGanz viele", justify='left')
  65. #self.bottomFrame.columnconfigure(0, weight=1) # Set weight to row and
  66. #self.bottomFrame.rowconfigure(0, weight=1) # column where the widget is
  67. self.bottomFrame.grid(column=0, row=2)
  68. self.bottomFrame.pack_propagate(0)
  69. self.bottomFrame.grid_propagate(0)
  70. self.bottomlabel.grid(padx=5,pady=5)
  71. def setInfoText(self, text):
  72. self.bottomlabel['text'] = text
  73. def setTitleText(self,text):
  74. self.toplabel['text'] = text
  75. class StartPage(Frame):
  76. def __init__(self, parent, controller):
  77. Frame.__init__(self, parent, height=250, width=500, bg="red")
  78. self.grid_propagate(0)
  79. self.pack_propagate(0)
  80. self.controller = controller
  81. self.leftFrame = Frame(self, bg="cyan", height=250, width=250)
  82. self.rightFrame = Frame(self, bg="blue", height=250, width=250)
  83. self.leftFrame.columnconfigure(0, weight=1) # Set weight to row and
  84. self.leftFrame.rowconfigure(0, weight=1) # column where the widget is
  85. self.leftFrame.grid_propagate(0)
  86. self.leftFrame.pack_propagate(0)
  87. self.rightFrame.columnconfigure(0, weight=1) # Set weight to row and
  88. self.rightFrame.rowconfigure(0, weight=1) # column where the widget is
  89. self.rightFrame.grid_propagate(0)
  90. self.rightFrame.pack_propagate(0)
  91. self.leftFrame.grid(column=0, row=0)
  92. self.rightFrame.grid(column=1, row=0)
  93. testBtn = Button(self.leftFrame, text="test", command=lambda: self.controller.actionPerformed("test"), height=6, width = 10)
  94. testBtn.grid()
  95. freeSpellingBtn = Button(self.rightFrame, text="freeSpelling", command=lambda: self.controller.actionPerformed("freeSpelling"), height=6, width = 10)
  96. freeSpellingBtn.grid()
  97. def adjustSize(self, height, width):
  98. self.leftFrame.configure(height=height, width= width)
  99. self.rightFrame.configure(height=height, width= width)
  100. class WorkingPage(Frame):
  101. def __init__(self, parent, controller):
  102. Frame.__init__(self, parent)
  103. self.controller = controller
  104. self.columnconfigure(0, weight=1) # Set weight to row and
  105. self.rowconfigure(0, weight=1) # column where the widget is
  106. stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=6, width = 10)
  107. stopBtn.grid()
  108. def adjustSize(self, height, width):
  109. pass