Skip to content

Instantly share code, notes, and snippets.

@heidisu
Last active February 18, 2021 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heidisu/76b1f1df03b43f8560b53c2a9a1f956c to your computer and use it in GitHub Desktop.
Save heidisu/76b1f1df03b43f8560b53c2a9a1f956c to your computer and use it in GitHub Desktop.
import tkinter as tk
import time
from tkinter import ttk
from threading import Thread
import random
from multiprocessing import Queue
def background_work(queue, rand):
time.sleep(rand.random() * 3)
msg = rand.random()
queue.put(msg)
background_work(queue, rand)
root = tk.Tk()
style = ttk.Style()
style.configure('TFrame', background='black')
style.configure('TLabel', background='black', foreground='white')
content = ttk.Frame(root, padding="20 20 20 20")
content.grid(column=0, row=0)
label = ttk.Label(content, text=" ", font=('Helvetica', 48))
label.grid(column = 0,row = 0)
def check_queue():
if not queue.empty():
msg = queue.get(0)
label.configure(text=msg)
root.after(1000, check_queue)
queue = Queue()
background_thread = Thread(target=background_work, args=[queue, random.Random()])
background_thread.start()
check_queue()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment