当前位置:网站首页>Tkinter window preload
Tkinter window preload
2022-07-05 17:48:00 【Smart-Space】
tkinter Window preload
introduction
A description of the premises , This is not a technical article , Just an experience sharing .
Source of problem
as everyone knows ,tkinter As Python The standard library of GUI library , One problem is that loading is slow , Relevant experiments have also basically proved this . however , In your project , What causes the window to start slowly is really tkinter The window itself ? It doesn't have to be .
In a general way tkinter Use
First , Let's recall many things first tkinter How the project is written tkinter The window appears at the right time .
The import Of import
Load classes and functions
Determination and tkinter Window related variables
load tkinter window
Obviously , stay tkinter Before the window appears ,Python There is still some work to be done . among , The first and third steps will take a long time . as a result of , Some libraries are really complicated , Such as PIL、Panda etc. , These have special pyd And the dynamic link library should be imported , And it has many source files ; On the other hand ,tkinter Windows need to create many controls , Especially for more complex projects , It takes a while to create the control .
In terms of creating controls ,customtkinter Well done , Adopt post load rendering ;TinUI The rendering loading speed of is very fast .
In one of my amateur projects , That is to say TinReader-TinGroup, There is a lot to load , Basic needs 3~6 second .
A role model
Look at Firefox next door , No, no matter three, seven, twenty-one , First show you a window frame ( background ) Do you ? The preload of other browsers is very large .
Since there are so many things to do , What else can I do , This is what I should do ?
It's very simple , Is to put tkinter Import first , The next line immediately shows tkinter window .
wait, I'm not kidding .
Specific measures
Show the window directly
There are few changes to be made . The details are as follows :
# Import tkinter
from tkinter import *
# Necessary variables
#title=...
#width=...
#height=...
# Use high DPI...
# create a window
root=Tk()
root.geometry('500x500')
root.update()
# Follow up operation
The notes have been written clearly .
My own project
stay TinReader Source code , All in all 1195 That's ok , You need to load pythonnet, PIL, tkwebview2, Dependencies ; Get initialization settings, etc . It will probably take 3~6 The second time .
Now? , Directly at the beginning :
# -*- coding: utf-8 -*-
from tkinter import Tk,Label,Frame,StringVar,scrolledtext,IntVar,Message,Radiobutton,Menu,Checkbutton,Canvas,\
Button as tkButton,LabelFrame,Toplevel,PhotoImage,Entry as tkEntry
import ctypes
# Pilot interface ---
ctypes.windll.shcore.SetProcessDpiAwareness(1)
TinTop=Tk()# main window
TinTop.withdraw()
sw = TinTop.winfo_screenwidth()
# Get the screen width
sh = TinTop.winfo_screenheight()
# Get the screen height
root=Toplevel()
root.geometry(str(sw//2-50)+'x'+str(sh-130)+'+0+10')
root.update()
#---
effect
If there is no conversion in this order , Then run from 、tkinter Blank window 、tkinter After the window is loaded , It was all empty , Using it may even feel like a crash .
The source code is really 1000+ Lines of code , The intermediate steps are indeed time-consuming , Now? , See at least one tkinter Blank windows are better than nothing .
Conclusion
This article is only for experience sharing .
Suggested items : Initialization takes tkinter project .
tkinter innovation
边栏推荐
- 排错-关于clion not found visual studio 的问题
- Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
- 查看自己电脑连接过的WiFi密码
- Disabling and enabling inspections pycharm
- Thesis reading_ Medical NLP model_ EMBERT
- mybash
- VBA drives SAP GUI to realize office automation (II): judge whether elements exist
- Flask solves the problem of CORS err
- Please tell me why some tables can find data by writing SQL, but they can't be found in the data map, and the table structure can't be found
- Sentinel-流量防卫兵
猜你喜欢
Rider set the highlighted side of the selected word, remove the warning and suggest highlighting
企业数字化发展中的六个安全陋习,每一个都很危险!
MySQL之知识点(七)
每日一练:关于日期的一系列
Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
Ten top automation and orchestration tools
MySQL之知识点(六)
漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
Thesis reading_ Chinese NLP_ LTP
网络威胁分析师应该具备的十种能力
随机推荐
力扣解法汇总729-我的日程安排表 I
Accuracy of BigDecimal Division
Kafaka技术第一课
Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
漫画:寻找无序数组的第k大元素(修订版)
一文读懂简单查询代价估算
论文阅读_中文NLP_LTP
MATLAB查阅
漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
数据访问 - EntityFramework集成
The comprehensive competitiveness of Huawei cloud native containers ranks first in China!
How to save the trained neural network model (pytorch version)
力扣解法汇总1200-最小绝对差
Abnormal recovery of virtual machine Oracle -- Xi Fenfei
Webapp development - Google official tutorial
Ten capabilities that cyber threat analysts should have
GFS分布式文件系统
rsync
Size_t 是无符号的
漫画:有趣的【海盗】问题