按下按钮时没有冻结TKINTER的解决方案
我面临一个问题,我想了解为什么会发生这个问题以及如何解决这个问题。我知道堆栈溢出的很多问题,这些问题在按下按钮时谈论了tkinter冻结,我看到了许多解决方案,但它对我不起作用,我想要一些帮助来了解如何解决此问题,我使用tkinter我尝试了一些应用程序使用Tiktoklive之类的库来学习新的东西,我试图制作一个按钮,当按下时,我尝试了一些我尝试过的信息螺纹,但不起作用,但试图看到有关使用队列的信息,我了解了排队,我看到了解决方案,我看到了解决方案喜欢使用多流程,但对我没有任何作用,所以我认为问题发生了,因为tiktoklive库可能是因为我们使用异步编程,所以我进行了一些搜索并看到了解决方案,但不起作用,我想要有助于了解更多如何解决此问题。
示例代码下面:
from tkinter import *
from threading import Thread
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold',
command=lambda: Thread(target=connect_with_tiktok_live()).start)
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
# from TikTokLive.types.events import
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 : # if live is ended
print('finished')
mainloop()
一些链接解决方案不适合我
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 *
from threading import Thread
root = Tk()
root.geometry("300x300")
get_information = Button(text="get", font='normal 30 bold',
command=lambda: Thread(target=connect_with_tiktok_live()).start)
get_information.pack()
def connect_with_tiktok_live():
# dependencies
import TikTokLive.types.events
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import ConnectEvent
# from TikTokLive.types.events import
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 : # if live is ended
print('finished')
mainloop()
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论