当前位置:网站首页>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
边栏推荐
- AD教程系列 | 4 - 创建集成库文件
- YOLOV5超参数设置与数据增强解析
- Guanghetong and anti international bring 5g R16 powerful performance to the AI edge computing platform based on NVIDIA Jetson Xavier nx
- Resample
- Illustration of ONEFLOW's learning rate adjustment strategy
- Transport layer TCP protocol and UDP protocol
- Dbeaver installation and configuration of offline driver
- Machine learning final exercises
- Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
- 【Unity3D】人机交互Input
猜你喜欢

LeetCode 19. 删除链表的倒数第 N 个结点

What is UWB in ultra-high precision positioning system

Illustration of ONEFLOW's learning rate adjustment strategy

How to select the data transmission format of instant messaging application

ROS notes (07) - Implementation of client and server

pycharm 导包错误没有警告

UWB超高精度定位系统原理图

A company crawling out of its grave

6.1 - 6.2 Introduction à la cryptographie à clé publique

2.< tag-动态规划和常规问题>lt.343. 整数拆分
随机推荐
Second day of deep learning and tensorfow
【quartz】从数据库中读取配置实现动态定时任务
《财富自由之路》读书之一点体会
2022.2.11
Selection of programming language
Illustration of ONEFLOW's learning rate adjustment strategy
Happy New Year!
UWB超高精度定位系统原理图
The beautiful scenery is natural, and the wonderful pen is obtained by chance -- how is the "wonderful pen" refined?
一个从坟墓里爬出的公司
Status of processes and communication between processes
A company crawling out of its grave
【Unity3D】人机交互Input
【Unity3D】刚体组件Rigidbody
Transport layer TCP protocol and UDP protocol
2.22.2.14
app 应用安装到手机,不显示图标,引发的思考
Muke.com actual combat course
MySql如何删除所有多余的重复数据
GD32F3x0 官方PWM驱动正频宽偏小(定时不准)的问题