当前位置:网站首页>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
边栏推荐
- ThreadPoolExecutor implements file uploading and batch inserting data
- Second day of deep learning and tensorfow
- Hash problem
- AD教程系列 | 4 - 创建集成库文件
- Happy New Year!
- Use to_ Numeric to numeric type
- Beidou navigation technology and industrial application of "chasing dreams in space and feeling for Beidou"
- YOLOv5-6.0的一些参数设置和特征图可视化
- UWB超高精度定位系统原理图
- PSIM software learning ---08 call of C program block
猜你喜欢

torchvision_ Transform (image enhancement)

A method of quickly transplanting library function code to register code by single chip microcomputer

Schematic diagram of UWB ultra high precision positioning system

Classic theory: detailed explanation of three handshakes and four waves of TCP protocol

PHP二维/多维数组按照指定的键值来进行升序和降序

0622 horse palm fell 9%

【Unity3D】人机交互Input

-Discrete Mathematics - Analysis of final exercises

Record a circular reference problem

LeetCode 19. Delete the penultimate node of the linked list
随机推荐
A method of quickly transplanting library function code to register code by single chip microcomputer
Multipass Chinese document - setup driver
MySql如何删除所有多余的重复数据
PowerShell runtime system IO exceptions
天才制造者:独行侠、科技巨头和AI|深度学习崛起十年
Computer Vision Tools Chain
Zuul implements dynamic routing
Pycharm package import error without warning
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
Statsmodels Library -- linear regression model
Collections and dictionaries
Créateur de génie: cavalier solitaire, magnat de la technologie et ai | dix ans d'apprentissage profond
Briefly describe the pitfalls of mobile IM development: architecture design, communication protocol and client
Why do many Shopify independent station sellers use chat robots? Read industry secrets in one minute!
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
【Latex】错误类型总结(持更)
Happy New Year!
SSH connected to win10 and reported an error: permission denied (publickey, keyboard interactive)
Floyd
Cookie and session Basics