Guest User

Untitled

a guest
Jan 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. def addBox():
  2. labelframe = Tkinter.Frame()
  3. labelframe.bind("<Add Input>", callback)
  4. labelframe.pack()
  5.  
  6. labelframe = Tkinter.Frame()
  7.  
  8. labelFrom = Tkinter.Label(labelframe, text= "from")
  9. labelFrom.grid(column=1, row=0)
  10. e = Tkinter.Entry(labelframe)
  11. e.grid(column=1, row=1)
  12.  
  13. labelTo = Tkinter.Label(labelframe, text= "to")
  14. labelTo.grid(column=2, row=0)
  15. e2 = Tkinter.Entry(labelframe)
  16. e2.grid(column=2, row=1)
  17.  
  18. labelframe.pack()
  19.  
  20. addboxButton = Button( root,text='<Add Time Input>', fg="Red",command="addBox")
  21. addboxButton.pack(side=Tkinter.TOP)
  22.  
  23. from Tkinter import *
  24.  
  25. #------------------------------------
  26.  
  27. def addBox():
  28. print "ADD"
  29.  
  30. ent = Entry(root)
  31. ent.pack()
  32.  
  33. all_entries.append( ent )
  34.  
  35. #------------------------------------
  36.  
  37. def showEntries():
  38.  
  39. for number, ent in enumerate(all_entries):
  40. print number, ent.get()
  41.  
  42. #------------------------------------
  43.  
  44. all_entries = []
  45.  
  46. root = Tk()
  47.  
  48. showButton = Button(root, text='Show all text', command=showEntries)
  49. showButton.pack()
  50.  
  51. addboxButton = Button(root, text='<Add Time Input>', fg="Red", command=addBox)
  52. addboxButton.pack()
  53.  
  54. root.mainloop()
  55.  
  56. #------------------------------------
  57.  
  58. from Tkinter import *
  59.  
  60. #------------------------------------
  61.  
  62. def addBox():
  63. print "ADD"
  64.  
  65. # I use len(all_entries) to get nuber of next free column
  66. next_column = len(all_entries)
  67.  
  68. # add label in first row
  69. lab = Label(frame_for_boxes, text=str(next_column+1))
  70. lab.grid(row=0, column=next_column)
  71.  
  72. # add entry in second row
  73. ent = Entry(frame_for_boxes)
  74. ent.grid(row=1, column=next_column)
  75.  
  76. all_entries.append( ent )
  77.  
  78. #------------------------------------
  79.  
  80. def showEntries():
  81.  
  82. for number, ent in enumerate(all_entries):
  83. print number, ent.get()
  84.  
  85. #------------------------------------
  86.  
  87. all_entries = []
  88.  
  89. root = Tk()
  90.  
  91. showButton = Button(root, text='Show all text', command=showEntries)
  92. showButton.pack()
  93.  
  94. addboxButton = Button(root, text='<Add Time Input>', fg="Red", command=addBox)
  95. addboxButton.pack()
  96.  
  97. frame_for_boxes = Frame(root)
  98. frame_for_boxes.pack()
  99.  
  100. root.mainloop()
  101.  
  102. #------------------------------------
  103.  
  104. from Tkinter import *
  105.  
  106. #------------------------------------
  107.  
  108. def addBox():
  109. print "ADD"
  110.  
  111. frame = Frame(root)
  112. frame.pack()
  113.  
  114. Label(frame, text='From').grid(row=0, column=0)
  115.  
  116. ent1 = Entry(frame)
  117. ent1.grid(row=1, column=0)
  118.  
  119. Label(frame, text='To').grid(row=0, column=1)
  120.  
  121. ent2 = Entry(frame)
  122. ent2.grid(row=1, column=1)
  123.  
  124. all_entries.append( (ent1, ent2) )
  125.  
  126. #------------------------------------
  127.  
  128. def showEntries():
  129.  
  130. for number, (ent1, ent2) in enumerate(all_entries):
  131. print number, ent1.get(), ent2.get()
  132.  
  133. #------------------------------------
  134.  
  135. all_entries = []
  136.  
  137. root = Tk()
  138.  
  139. showButton = Button(root, text='Show all text', command=showEntries)
  140. showButton.pack()
  141.  
  142. addboxButton = Button(root, text='<Add Time Input>', fg="Red", command=addBox)
  143. addboxButton.pack()
  144.  
  145. root.mainloop()
  146.  
  147. #------------------------------------
  148.  
  149. class OptionsView(Frame):
  150. """Frame for options in main window"""
  151. def __init__(self, x, y, parent):
  152. Frame.__init__(self, parent)
  153. self.x = x
  154. self.y = y
  155. self.placed = False
  156. self.hidden = False
  157. self.btn = Button(self, text = 'Button attached to the frame ..', command = lambda: print('Button in frame clicked ..')).pack()
  158. def pack(self):
  159. self.place(x = self.x, y = self.y)
  160. self.placed = True
  161. def toggle_view(self):
  162. if self.hidden:
  163. self.pack()
  164. self.hidden = False
  165. else:
  166. self.place_forget()
  167. self.hidden = True
  168.  
  169. if __name__ == '__main__':
  170. def m_frame():
  171. if val.get() and not options_frame.placed:
  172. print('Showing Frame ..')
  173. options_frame.pack()
  174. else:
  175. print('Toggling Frame ..')
  176. options_frame.toggle_view()
  177.  
  178. root = Tk()
  179. root.geometry('300x400+500+600')
  180. root.title('Testing Hiding Frames ..')
  181. options_frame = OptionsView(200, 300, root)
  182.  
  183. val = BooleanVar(value = False)
  184. Checkbutton(text = 'View more Options ..', var = val, command = m_frame).place(x=root.winfo_height()/2, y=root.winfo_width()/2)
  185.  
  186. try: root.mainloop()
  187. except e: showerror('Error!', 'It seems there's a problem ..', str(e))
  188.  
  189. from Tkinter import *
  190.  
  191. frame = Frame(root)
  192. frame.pack()
  193.  
  194. Label(frame, text='From').grid(row=0, column=0)
  195.  
  196. ent1 = Entry(frame)
  197. ent1.grid(row=1, column=0)
  198.  
  199. Label(frame, text='To').grid(row=0, column=1)
  200.  
  201. ent2 = Entry(frame)
  202. ent2.grid(row=1, column=1)
  203.  
  204. all_entries.append( (ent1, ent2) )
  205.  
  206. for number, (ent1, ent2) in enumerate(all_entries):
  207. print number, ent1.get(), ent2.get()
Add Comment
Please, Sign In to add comment