Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import random
- import threading
- start_status = False
- calc_list=[]
- rand = random.Random()
- def randomGenerator():
- if start_status:
- outputs = []
- Out1= rand.randrange(0,100,1)
- Out2= rand.randrange(0,100,1)
- outputs.append(Out1)
- outputs.append(Out2)
- output_1.set(Out1) #to display in the GUI
- output_2.set(Out2)
- calc_list.append(outputs) #i am trying to rest this to empty #when i press start after pressing stopping.
- print(calc_list)
- win.after(1000, randomGenerator)
- def start_me():
- global start_status
- start_status = True
- stopButton.config(state="normal")
- startButton.config(state="disabled")
- calcButton.config(state="disabled")
- calc_list=[] #it doesn't work
- def stop_me():
- global start_status
- start_status = False
- startButton.config(state="normal")
- stopButton.config(state="disabled")
- calcButton.config(state="normal")
- def get_max_list(calc_list):
- return [max(x) for x in zip(*calc_list)]
- win = tk.Tk()
- win.geometry('800x800')
- output_1 = tk.StringVar()
- output_2 = tk.StringVar()
- output_1_label = tk.Label(win, textvariable=output_1)
- output_1_label.place(x=200, y=100)
- output_2_label = tk.Label(win, textvariable=output_2)
- output_2_label.place(x=200, y=200)
- startButton = tk.Button(win, text="Start" command = lambda:threading.Thread(target = start_me).start())
- startButton.place(x=200, y=500)
- stopButton = tk.Button(win, text="Stop", state=tk.DISABLED, command= lambda:threading.Thread(target = stop_me).start())
- stopButton.place(x=200, y=600)
- calcButton = tk.Button(win, text="calculate", state=tk.DISABLED, command= lambda:threading.Thread(target = get_max_list).start())
- calcButton.place(x=200, y=700)
- win.after(1000, randomGenerator)
- win.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement