当前位置:网站首页>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
边栏推荐
- C # realizes crystal report binding data and printing 3-qr code barcode
- Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
- ELK日志分析系统
- 查看自己电脑连接过的WiFi密码
- Domain name resolution, reverse domain name resolution nbtstat
- Webapp development - Google official tutorial
- SQL Server(2)
- Redis基础
- 解决“双击pdf文件,弹出”请安装evernote程序
- Server configuration jupyter environment
猜你喜欢

IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.

LeetCode每日一题:合并两个有序数组

leetcode每日一练:旋转数组

Mongodb (quick start) (I)

Rider set the highlighted side of the selected word, remove the warning and suggest highlighting

Oracle Recovery Tools ----oracle数据库恢复利器

Matlab reference

mybash

Kafaka technology lesson 1

神经网络自我认知模型
随机推荐
C # mixed graphics and text, written to the database in binary mode
Is it safe to open an account online? What is the general interest rate of securities financing?
This 17-year-old hacker genius cracked the first generation iPhone!
漫画:寻找无序数组的第k大元素(修订版)
删除数组中的某几个元素
Disabling and enabling inspections pycharm
Vulnerability recurrence - 48. Command injection in airflow DAG (cve-2020-11978)
Thesis reading_ Medical NLP model_ EMBERT
漫画:一道数学题引发的血案
服务器配置 jupyter环境
普通程序员看代码,顶级程序员看趋势
Teamcenter 消息注册前操作或後操作
排错-关于clion not found visual studio 的问题
SQL Server(2)
Use QT designer interface class to create two interfaces, and switch from interface 1 to interface 2 by pressing the key
How to save the trained neural network model (pytorch version)
Cartoon: interesting [pirate] question
Which platform of outer disk gold is regular and safe, and how to distinguish it?
Cmake tutorial step6 (add custom commands and generate files)
7 pratiques devops pour améliorer la performance des applications