我面临一个问题,我想了解为什么会发生这个问题以及如何解决这个问题。我知道堆栈溢出的很多问题,这些问题在按下按钮时谈论了tkinter冻结,我看到了许多解决方案,但它对我不起作用,我想要一些帮助来了解如何解决此问题,我使用tkinter我尝试了一些应用程序使用诸如tiktoklive之类的库来学习新的东西,我尝试制作一个按钮,当按下时,我尝试了一些我尝试过的信息螺纹,但不使用,并且试图看到有关使用queue的信息,我了解 queue < /strong>和我看到了使用多流程之类的解决方案,但对我没有任何作用,所以我认为由于tiktoklive库而发生的问题可能是因为我们使用 async 编程,所以我做了有些搜索和看到解决方案但不起作用,我想提供更多帮助,以了解如何解决此问题。
示例代码下面:
from tkinter import *
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold', command=lambda: connect_with_tiktok_live())
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
username = "put the username of tiktok live"
# Instantiate the client with the user's username
client: TikTokLiveClient = TikTokLiveClient(
unique_id=username, **({
"process_initial_data": False,
"enable_extended_gift_info": True,
}))
@client.on('connect')
async def on_connect(_: ConnectEvent):
print("Connected to Room ID: ", client.room_id)
# Run the client and block the main thread
# await client.start() to run non-blocking
try:
return client.run()
except FailedConnection: # if live is ended
print('finished')
mainloop()
gif problrm:
一些链接解决方案不适合我
在运行异步任务时,我如何防止tkinter gui冻结?
< a href =“ https://stackoverflow.com/questions/185222171/tkinter-window-says-not-responding-but-code-isponding-code-is-running/68897016#68897016”
如何轻松避免tkinter冷冻?
如何在tkinter的背景下运行一个函数
tkinter:如何使用线程来防止主事件循环循环循环来自“冷冻”
I face an issue and I want to understand why this problem happens and how to solve this problem. I know a lot of questions on stack overflow that talk about tkinter freeze when button pressed I saw many solutions but it is not working for me and I want some help to understand how to solve this problem, I work on some app using tkinter I trying use libraries like TikTokLive to learn new something and I tried to make a button that when pressed gives some information I tried threading but not working and tried to see about use queue and I understand the queue and I saw solutions like use multiprocess but nothing works for me so I thought that problem happens because of the tiktoklive library may be because we use async programming so I made some search and saw solution but not working, I want to some help to understand more how to solve this problem.
Sample code below:
from tkinter import *
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold', command=lambda: connect_with_tiktok_live())
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
username = "put the username of tiktok live"
# Instantiate the client with the user's username
client: TikTokLiveClient = TikTokLiveClient(
unique_id=username, **({
"process_initial_data": False,
"enable_extended_gift_info": True,
}))
@client.on('connect')
async def on_connect(_: ConnectEvent):
print("Connected to Room ID: ", client.room_id)
# Run the client and block the main thread
# await client.start() to run non-blocking
try:
return client.run()
except FailedConnection: # if live is ended
print('finished')
mainloop()
gif problrm:

some links solution not working for me
How can I prevent a tkinter Gui from freezing while an async task is running?
python running task in the background while allowing tkinter to be active
Tkinter window says (not responding) but code is running
How to easily avoid Tkinter freezing?
How to run a function in the background of tkinter
Tkinter: How to use threads to preventing main event loop from "freezing"
发布评论
评论(1)
您可以在此处使用
threading.thread
方法。You can use multithreading here using
threading.Thread
method.