Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. self.firstRadioButton = Radiobutton(self.__canvas, text="ONE", fg='white', bg=BACKGROUND_COLOR, variable=self.selectedONE, value=1)
  2.  
  3. self.secondRadioButton = Radiobutton(self.__canvas, text="TWO", fg='white', bg=BACKGROUND_COLOR, variable=self.selectedTWO, value=2)
  4.  
  5. import tkinter
  6.  
  7.  
  8. # function that is called when you select a certain radio button
  9. def selected():
  10. print(var.get())
  11.  
  12.  
  13. root = tkinter.Tk()
  14.  
  15.  
  16. var = tkinter.StringVar() #used to get the 'value' property of a tkinter.Radiobutton
  17.  
  18. # Note that I added a command to each radio button and a different 'value'
  19. # When you press a radio button, its corresponding 'command' is called.
  20. # In this case, I am linking both radio buttons to the same command: 'selected'
  21.  
  22. rb1 = tkinter.Radiobutton(text='Radio Button 1', variable=var, value="Radio 1", command=selected)
  23. rb1.pack()
  24. rb2 = tkinter.Radiobutton(text='Radio Button 2', variable=var, value="Radio 2", command=selected)
  25. rb2.pack()
  26.  
  27.  
  28. root.mainloop()
  29.  
  30. self.secondRadioButton.bind('<ButtonRelease-1>', self.__function_name_that_should_run_when_radiobtn_selected)
  31.  
  32. #!/usr/bin/env python
  33.  
  34. from Tkinter import Tk, Frame, Label, Entry, Button, TOP, LEFT, RIGHT, X, YES, END,
  35. Radiobutton, StringVar,
  36. Canvas
  37.  
  38.  
  39. def padded(text):
  40. # return a padded 80-column string
  41. line = text
  42. line += (30 - len(text)) * ' '
  43. return line
  44.  
  45.  
  46. class PRB:
  47. def __init__(self, master):
  48. # self.entries = {}
  49. frame = Frame(master)
  50. frame.pack(side=TOP, fill=X, expand=YES, padx=5, pady=5)
  51. root.geometry("360x220")
  52.  
  53. self.w = Canvas(master, width=560, height=400)
  54. self.w.pack()
  55. self.w.create_line(11, 5, 330, 5)
  56. self.w.create_line(11, 37, 330, 37)
  57. self.w.create_line(11, 73, 330, 73)
  58. self.w.create_line(11, 5, 11, 73)
  59. self.w.create_line(110, 5, 110, 73)
  60. self.w.create_line(330, 5, 330, 73)
  61. self.w.create_line(275, 5, 275, 73)
  62.  
  63. self.ent1 = Entry(master)
  64. self.ent1.pack(side=RIGHT, expand=YES, fill=X)
  65. self.ent1.place(x=130, y=100, width=130)
  66. self.ent1.delete(0, END)
  67. self.ent1.insert(0, 'Enter a pass to pass!')
  68. self.ent1.focus_set()
  69.  
  70. self.ent2 = Entry(master)
  71. self.ent2.pack(side=RIGHT, expand=YES, fill=X)
  72. self.ent2.place(x=130, y=140, width=130)
  73. self.ent2.delete(0, END)
  74. self.ent2.insert(0, 'Enter a pass to pass!')
  75. self.ent2.focus_set()
  76.  
  77. self.v = StringVar()
  78. self.rb1 = Radiobutton(root, text="Type 1", variable=self.v, value=1)
  79. self.rb1.pack(side=TOP)
  80. self.rb1.place(x=20, y=20)
  81.  
  82. self.rb2 = Radiobutton(root, text="Type 2", variable=self.v, value=2)
  83. self.rb2.pack(side=TOP)
  84. self.rb2.place(x=20, y=55)
  85.  
  86. self.b1 = Button(master, width=10, text='Test_X', command=self.Test_X)
  87. self.b1.pack(side=RIGHT)
  88. self.b1.place(x=20, y=100)
  89.  
  90. self.b2 = Button(master, width=10, text='Test_Y', command=self.Test_Y)
  91. self.b2.pack(side=RIGHT)
  92. self.b2.place(x=20, y=140)
  93.  
  94. self.quit = Button(master, width=10, text='Cancel', bg='red', fg='white', command=root.quit)
  95. self.quit.pack(side=LEFT)
  96. self.quit.place(x=20, y=180)
  97.  
  98. self.pasMSG = 'PASS'
  99. self.pasMSG2 = 'PASS'
  100.  
  101. self.msg = padded('Please, select a type!')
  102. self.l1 = Label(root, text=self.msg, anchor='w')
  103. self.l1.pack()
  104. self.l1.place(x=120, y=20)
  105.  
  106. self.l2 = Label(master, text=self.msg, anchor='w')
  107. self.l2.pack(side=RIGHT)
  108. self.l2.place(x=120, y=55)
  109.  
  110. self.p1 = Label(master, text=self.pasMSG, anchor='w')
  111. self.p1.pack(side=RIGHT)
  112. self.p1.place(x=285, y=20)
  113.  
  114. self.p2 = Label(master, text=self.pasMSG2, anchor='w')
  115. self.p2.pack(side=RIGHT)
  116. self.p2.place(x=285, y=55)
  117.  
  118.  
  119. def Test_X(self):
  120. if self.v.get() == '1':
  121. msg = padded('Type 1 Test_X')
  122. self.l1 = Label(root, text=msg, anchor='w')
  123. self.l1.pack()
  124. self.l1.place(x=120, y=20)
  125.  
  126. if self.ent1.get().strip() == 'pass':
  127. pasMSG = padded('PASS!')
  128. co = 'green'
  129. else:
  130. pasMSG = padded('FAIL :(')
  131. co = 'red'
  132. self.p1 = Label(root, text=pasMSG, bg=co, fg='white', anchor='w')
  133. self.p1.pack(side=RIGHT)
  134. self.p1.place(x=285, y=20, width=40)
  135. # self.p1.config(height = )
  136.  
  137. elif self.v.get() == '2':
  138. msg = padded('Type 2 Test_X')
  139. self.l1 = Label(root, text=msg, anchor='w')
  140. self.l1.pack()
  141. self.l1.place(x=120, y=20)
  142.  
  143. if self.ent1.get().strip() == 'pass':
  144. pasMSG = padded('PASS!')
  145. co = 'green'
  146. else:
  147. pasMSG = padded('FAIL :(')
  148. co = 'red'
  149. self.p1 = Label(root, text=pasMSG, bg=co, fg='white', anchor='w')
  150. self.p1.pack(side=RIGHT)
  151. self.p1.place(x=285, y=20, width=40)
  152.  
  153. def Test_Y(self):
  154. if self.v.get() == '1':
  155. msg2 = padded('Type 1 Test_Y')
  156. self.l2 = Label(root, text=msg2, anchor='w')
  157. self.l2.pack()
  158. self.l2.place(x=120, y=55)
  159.  
  160. if self.ent2.get().strip() == 'pass':
  161. pasMSG2 = padded('PASS')
  162. co = 'green'
  163. else:
  164. pasMSG2 = padded('FAIL :(')
  165. co = 'red'
  166. self.p2 = Label(root, text=pasMSG2, bg=co, fg='white', anchor='w')
  167. self.p2.pack(side=RIGHT)
  168. self.p2.place(x=285, y=55, width=40)
  169. # self.p1.config(height = )
  170.  
  171. elif self.v.get() == '2':
  172. msg2 = padded('Type 2 Test_Y')
  173. self.l2 = Label(root, text=msg2, anchor='w')
  174. self.l2.pack()
  175. self.l2.place(x=120, y=55)
  176.  
  177. if self.ent2.get().strip() == 'pass':
  178. pasMSG2 = padded('PASS!')
  179. co = 'green'
  180. else:
  181. pasMSG2 = padded('FAIL :(')
  182. co = 'red'
  183. self.p2 = Label(root, text=pasMSG2, bg=co, fg='white', anchor='w')
  184. self.p2.pack(side=RIGHT)
  185. self.p2.place(x=285, y=55, width=40)
  186.  
  187.  
  188. if __name__ == '__main__':
  189. root = Tk()
  190. prb = PRB(root)
  191. root.title('put "pass" in the entries to pass the test!')
  192. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement