当前位置:网站首页>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
边栏推荐
- EPM相关
- How to save the trained neural network model (pytorch version)
- Cartoon: interesting [pirate] question
- Cmake tutorial step6 (add custom commands and generate files)
- tkinter窗口预加载
- 2022年信息系统管理工程师考试大纲
- WebApp开发-Google官方教程
- 使用QT设计师界面类创建2个界面,通过按键从界面1切换到界面2
- Disabling and enabling inspections pycharm
- Disabling and enabling inspections pycharm
猜你喜欢

Compter le temps d'exécution du programme PHP et définir le temps d'exécution maximum de PHP

神经网络自我认知模型

提高应用程序性能的7个DevOps实践

ELK日志分析系统

mybash

Check the WiFi password connected to your computer

论文阅读_中文NLP_LTP

EPM相关

Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?

Oracle recovery tools -- Oracle database recovery tool
随机推荐
Tita performance treasure: how to prepare for the mid year examination?
Simple query cost estimation
如何保存训练好的神经网络模型(pytorch版本)
WebApp开发-Google官方教程
[binary tree] insufficient nodes on the root to leaf path
Ten capabilities that cyber threat analysts should have
服务器配置 jupyter环境
Troubleshooting - about clip not found Visual Studio
Teamcenter 消息注册前操作或後操作
Force deduction solution summary 729- my schedule I
数据访问 - EntityFramework集成
VBA drives SAP GUI to realize office automation (II): judge whether elements exist
每日一练:关于日期的一系列
漫画:寻找无序数组的第k大元素(修订版)
Cloud security daily 220705: the red hat PHP interpreter has found a vulnerability of executing arbitrary code, which needs to be upgraded as soon as possible
力扣解法汇总729-我的日程安排表 I
Complete solution instance of Oracle shrink table space
中国银河证券开户安全吗 开户后多久能买股票
Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
查看自己电脑连接过的WiFi密码