当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Ant financial's sudden wealth has not yet begun, but the myth of zoom continues!
请问下为啥有的表写sql能查到数据,但在数据地图里查不到啊,查表结构也搜不到
Action avant ou après l'enregistrement du message teamcenter
每日一练:关于日期的一系列
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
Six bad safety habits in the development of enterprise digitalization, each of which is very dangerous!
Winedt common shortcut key modify shortcut key latex compile button
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
论文阅读_中文NLP_LTP
Read the history of it development in one breath
Cmake tutorial step6 (add custom commands and generate files)
C (WinForm) the current thread is not in a single threaded unit, so ActiveX controls cannot be instantiated
Teamcenter 消息注册前操作或后操作
Webapp development - Google official tutorial
MATLAB查阅
Use QT designer interface class to create two interfaces, and switch from interface 1 to interface 2 by pressing the key
Oracle Recovery Tools ----oracle数据库恢复利器
Which platform of outer disk gold is regular and safe, and how to distinguish it?
GFS分布式文件系统
Is it safe for China Galaxy Securities to open an account? How long can I buy stocks after opening an account