Last active
February 18, 2021 19:03
-
-
Save heidisu/76b1f1df03b43f8560b53c2a9a1f956c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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