当前位置:网站首页>Practical cases | getting started and mastering tkinter+pyinstaller
Practical cases | getting started and mastering tkinter+pyinstaller
2022-06-26 05:07:00 【JERRY__ JIN】
Practical cases | Getting started Tkinter+Pyinstaller
Made a Tkinter+Pyinstaller A small example of linkage , Record the experimental problems here
One 、Tkinter
visualization GUI
1. Install the parts :
python It comes with its own
2. Basic course :
Common modules
https://www.runoob.com/python/python-gui-tkinter.html
Emphasis on the :filedialog yes tkinter File dialog box in
- Use :
- The import module :import tkinter.filedialog
- Select the format of the file dialog box :
- tkinter.filedialog.asksaveasfilename(): Choose what file name to save , Return the filename
- tkinter.filedialog.asksaveasfile(): Choose what file to save , Create a file and return the file stream object
- tkinter.filedialog.askopenfilename(): Choose what file to open , Return the filename
- tkinter.filedialog.askopenfile(): Choose what file to open , return IO Stream object
- tkinter.filedialog.askdirectory(): Choose a directory , Return directory name
- tkinter.filedialog.askopenfilenames(): Select to open multiple files , Returns multiple file names as tuples
- tkinter.filedialog.askopenfiles(): Select to open multiple files , Returns multiple items as a list IO Stream object
import tkinter.filedialog as filedialog
# Return the filename
filenames = filedialog.askopenfilenames()
In this case , There are some deficiencies , That is, the front end and the back end are not separated ( Because it won't ...) Just write it together
3. Complete code :
from tkinter import *
import tkinter.filedialog as filedialog
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
# Show all columns
pd.set_option('display.max_columns', None)
# --- Logic implementation ---
def data_range(require_data):
if '±' in require_data:
print(" Scope of requirements :", require_data)
base = require_data.split('±')[0]
volatility = require_data.split('±')[1]
base_up = float(base) + float(volatility)
base_down = float(base) - float(volatility)
return base_up, base_down
def read_excel(path):
data_xls = pd.ExcelFile(path)
# sheet The name of the table
print(data_xls.sheet_names)
data = {
}
for name in data_xls.sheet_names:
df = data_xls.parse(sheetname=name)
data[name] = df
# print(df)
# print(name)
return data
def get_select_dataset(sheet_path, require_path,save_path):
dataset = read_excel(sheet_path)
select_dfs = []
with open(require_path, 'r', encoding='utf-8') as f:
res_ls = f.readlines()
for i, res in enumerate(res_ls):
sheet_name = res.split(' ')[0]
require_data = res.split(' ')[1].split('\n')[0]
df = dataset[sheet_name]
# Table to be filtered
print(f' Serial number :{
i+1} \t Table to be filtered :{
sheet_name}')
# Scope of requirements
base_up, base_down = data_range(require_data)
print(df)
select_df = df[(df['Retention time (min)'] >= base_down) & (df['Retention time (min)'] <= base_up)]
# Filtered data
print(' Filtered data :')
print(select_df)
select_df['sheet name'] = sheet_name
select_dfs.append(select_df)
final_df = pd.concat(select_dfs)
final_df.to_csv(save_path,index=False)
s = f' Filtering complete , Please check the results :{
save_path}'
txt.insert(END, s) # Additional display of operation results
# ------ Window implementation ----------------
def xz1():
filenames = filedialog.askopenfilenames()
if len(filenames) != 0:
string_filename =filenames[0]
txt1.insert(END,string_filename)
else:
txt1.insert(END," You have not selected any files ")
def xz2():
filenames = filedialog.askopenfilenames()
if len(filenames) != 0:
string_filename = filenames[0]
txt2.insert(END,string_filename)
else:
txt2.insert(END," You have not selected any files ")
root = Tk()
root.geometry('700x540')
root.title(' Table condition filter _v1 ( Special for sister min )')
lb1 = Label(root, text=' Select the table file ')
lb1.place(relx=0.1, rely=0.1, relwidth=0.2, relheight=0.1)
lb2 = Label(root, text=' Select requirements document ')
lb2.place(relx=0.4, rely=0.1, relwidth=0.2, relheight=0.1)
lb3 = Label(root, text=' Fill in the save file name (.csv ending )')
lb3.place(relx=0.7, rely=0.1, relwidth=0.2, relheight=0.1)
txt1 = Text(root)
txt1.place(relx=0.1, rely=0.2, relwidth=0.2, relheight=0.1)
txt2 = Text(root)
txt2.place(relx=0.4, rely=0.2, relwidth=0.2, relheight=0.1)
input1 = Entry(root)
input1.place(relx=0.7, rely=0.2, relwidth=0.2, relheight=0.1)
btn1 = Button(root,text=" Select the table to filter ",command=xz1)
btn1.place(relx=0.1, rely=0.4,relwidth=0.2,relheight=0.05)
btn2 = Button(root,text=" Select requirements document ",command=xz2)
btn2.place(relx=0.4, rely=0.4,relwidth=0.2,relheight=0.05)
# Screening rules
btn3 = Button(root, text=' Start the calculation ', command=lambda: get_select_dataset(txt1.get('0.0','end').split('\n')[0],txt2.get('0.0','end').split('\n')[0],input1.get()))
btn3.place(relx=0.7, rely=0.4, relwidth=0.2,relheight=0.05)
# Prompt box
lb = Label(root, text=' Prompt box ')
lb.place(relx=0.1, rely=0.5, relwidth=0.2, relheight=0.1)
# In the vertical top-down position of the form 60% From the beginning , Relative height of the form 40% High text box
txt = Text(root)
txt.place(relx=0.1,rely=0.6, relwidth=0.8,relheight=0.3)
root.mainloop()
Two 、Pyinstaller
Pyinstaller pack Python Program , There are many answers to questions on the Internet , I'm so angry !
1. Install the parts :
pip install pyinstaller
Possible problems :
Installed pyinstall Tips ‘pyinstall’ Not an internal or external command , It's not a runnable program Or batch file solutions
Never mind , Give it a try pyinstaller
Now generate exe My command is pyinstaller, instead of pyinstall !!! Be careful !!!
2. Generate ico Format
3. Command line
Basic commands :
# Be careful !!! yes pyinstaller
pyinstaller -F -i picture .ico file .py
Hide the console
# Be careful !!! yes pyinstaller
pyinstaller -F -w -i picture .ico file .py
Generated exe stay dist In the folder
边栏推荐
- 微服务之间的Token传递之一@Feign的token传递
- Schematic diagram of UWB ultra high precision positioning system
- Differences between TCP and UDP
- UWB超高精度定位系统架构图
- 2022.2.16
- Day4 branch and loop jobs
- 天才制造者:獨行俠、科技巨頭和AI|深度學習崛起十年
- Solution to back-off restarting failed container
- UWB ultra high precision positioning system architecture
- Codeforces Round #800 (Div. 2)
猜你喜欢
百度API地图的标注不是居中显示,而是显示在左上角是怎么回事?已解决!
Use fill and fill in Matplotlib_ Between fill the blank area between functions
-Discrete Mathematics - Analysis of final exercises
【Unity3D】刚体组件Rigidbody
86.(cesium篇)cesium叠加面接收阴影效果(gltf模型)
AD教程系列 | 4 - 创建集成库文件
How MySQL deletes all redundant duplicate data
DBeaver 安装及配置离线驱动
pycharm 导包错误没有警告
《财富自由之路》读书之一点体会
随机推荐
Use fill and fill in Matplotlib_ Between fill the blank area between functions
2.< tag-动态规划和常规问题>lt.343. 整数拆分
YOLOv5-6.0的一些参数设置和特征图可视化
Rsync common error messages (common errors on the window)
ROS notes (07) - Implementation of client and server
Muke.com actual combat course
Codeforces Round #800 (Div. 2)
Simple application of KMP
Some parameter settings and feature graph visualization of yolov5-6.0
Selection of programming language
A beginner's entry is enough: develop mobile IM from zero
PHP one sentence Trojan horse
6.1 - 6.2 introduction to public key cryptography
Why does the mobile IM based on TCP still need to keep the heartbeat alive?
YOLOV5超参数设置与数据增强解析
-Discrete Mathematics - Analysis of final exercises
Technical problems to be faced in mobile terminal im development
Using Matplotlib to add an external image at the canvas level
Comment enregistrer une image dans une applet Wechat
Computer Vision Tools Chain