Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import tkinter as tk
  2. import random
  3. import threading
  4. start_status = False
  5. calc_list=[]
  6. rand = random.Random()
  7.  
  8. def randomGenerator():
  9. if start_status:
  10. outputs = []
  11. Out1= rand.randrange(0,100,1)
  12. Out2= rand.randrange(0,100,1)
  13. outputs.append(Out1)
  14. outputs.append(Out2)
  15.  
  16. output_1.set(Out1) #to display in the GUI
  17. output_2.set(Out2)
  18. calc_list.append(outputs) #i am trying to rest this to empty #when i press start after pressing stopping.
  19. print(calc_list)
  20. win.after(1000, randomGenerator)
  21.  
  22. def start_me():
  23. global start_status
  24. start_status = True
  25. stopButton.config(state="normal")
  26. startButton.config(state="disabled")
  27. calcButton.config(state="disabled")
  28. calc_list=[] #it doesn't work
  29.  
  30. def stop_me():
  31. global start_status
  32. start_status = False
  33. startButton.config(state="normal")
  34. stopButton.config(state="disabled")
  35. calcButton.config(state="normal")
  36.  
  37. def get_max_list(calc_list):
  38. return [max(x) for x in zip(*calc_list)]
  39. win = tk.Tk()
  40. win.geometry('800x800')
  41.  
  42.  
  43. output_1 = tk.StringVar()
  44. output_2 = tk.StringVar()
  45. output_1_label = tk.Label(win, textvariable=output_1)
  46. output_1_label.place(x=200, y=100)
  47.  
  48. output_2_label = tk.Label(win, textvariable=output_2)
  49. output_2_label.place(x=200, y=200)
  50.  
  51. startButton = tk.Button(win, text="Start" command = lambda:threading.Thread(target = start_me).start())
  52. startButton.place(x=200, y=500)
  53.  
  54. stopButton = tk.Button(win, text="Stop", state=tk.DISABLED, command= lambda:threading.Thread(target = stop_me).start())
  55. stopButton.place(x=200, y=600)
  56.  
  57. calcButton = tk.Button(win, text="calculate", state=tk.DISABLED, command= lambda:threading.Thread(target = get_max_list).start())
  58. calcButton.place(x=200, y=700)
  59.  
  60. win.after(1000, randomGenerator)
  61. win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement