Python - Tkinter & while цикл одновременно - PullRequest
0 голосов
/ 10 июня 2018

Я начинающий питон.Я хочу знать, есть ли способ запустить цикл одновременно с запуском окна tkinter.

from tkinter import *

root = Tk()
root.geometry("300x280")
root.title("Test")
Window=Frame(root,relief="raise", bg="#282d38")
Window.pack(side=TOP)

root.mainloop()

while True:
    print("hi")

Я хочу, чтобы цикл работал во время работы моего окна.

1 Ответ

0 голосов
/ 10 июня 2018

Threading это то, что вам нужно.https://www.tutorialspoint.com/python/python_multithreading.htm

Пример:

import thread
import time

# Define a function for the thread
def print_time( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
      print "%s: %s" % ( threadName, time.ctime(time.time()) )

# Create two threads as follows
try:
   thread.start_new_thread( print_time, ("Thread-1", 2, ) )
   thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...