我开始构建python tkinter gui,问题是,在gui中添加了许多功能之后,加载看起来真的很丑。启动主循环时,在加载小部件之前,空白窗口会显示几毫秒,其他顶级窗口也会发生同样的情况(除了具有很少静态元素且不需要更新的窗口)。
有没有一种方法可以“预加载”窗口,以便当我调用它时,它可以顺利启动?
root = MyTkRoot()
root.build_stuff_before_calling()
root.mainloop() # Smooth without widget loading lag
Run Code Online (Sandbox Code Playgroud)
from root_gui import Root
import threading
from time import sleep
from data_handler import DataHandler
def handle_conn():
DataHandler.try_connect()
smtp_client.refresh()
def conn_manager(): # Working pretty well
while 'smtp_client' in locals():
sleep(3)
handle_conn()
smtp_client = Root()
handle_conn()
MyConnManager = threading.Thread(target=conn_manager)
MyConnManager.start() # Thanks to the second thread, the tk window doesn't have to wait for 3 seconds before loading the widgets.
smtp_client.mainloop()
Run Code Online (Sandbox Code Playgroud)
我目前正在学习C编程,因为我是一个python程序员,我不完全确定C的内部工作原理.我只是偶然发现了一个非常奇怪的事情.
void test_realloc(){
// So this is the original place allocated for my string
char * curr_token = malloc(2*sizeof(char));
// This is really weird because I only allocated 2x char size in bytes
strcpy(curr_token, "Davi");
curr_token[4] = 'd';
// I guess is somehow overwrote data outside the allocated memory?
// I was hoping this would result in an exception ( I guess not? )
printf("Current token > %s\n", curr_token);
// Looks like it's still printable, wtf???
char *new_token = realloc(curr_token, …Run Code Online (Sandbox Code Playgroud)