我最近完成了程序,尝试将图标与独立的exe文件打包在一起,但是当我将其发送出去时,由于文件路径不可用,无法打开exe。发送后,它正在查找我的文件中的图标,而不是用户文件中的图标。但是,当他们下载该图标时,将包括该图标。
打开exe时,因为它可以找到.ico文件,所以我没有任何问题。
我跑步:pyinstaller -w -F -ipiggy.ico Animals.py
代码如下:
import requests
from bs4 import BeautifulSoup
import urllib3
urllib3.disable_warnings()
import tkinter as tk
from tkinter import *
from tkinter import ttk
def AGU():
def Animals(Animal, textofbutton):
Animal2=Animal.replace(' ','-')
page = requests.get('https://a-z-animals.com/animals/' + Animal2.lower(),verify=False)
soup = BeautifulSoup(page.text, 'html.parser')
(soup.prettify())
(soup.find_all('table',class_="az-facts"))
for tr in soup.find_all('table', class_="az-facts"):
tds = tr.find_all('td')
mylist = []
for information in tds:
mylist.append(information.text)
for position, val in enumerate(mylist):
if position != 0:
if textofbutton in mylist[position-1]:
valueani = mylist[position]
label1.configure(text= valueani)
break
else:
label1.configure(text= 'Information not available')
#----------------------------------------------------------------
def gui():
guiwindow=tk.Tk()
guiwindow.title('Animal Information')
guiwindow.geometry('425x225')
guiwindow.config(background = "#a0d4d6")
input1= Entry(guiwindow, width=10)
input1.grid(column=1,row=1)
frame2 = Frame(guiwindow, width=250, height = 280, highlightthickness=2, highlightbackground="#111")
frame2.grid(row=2, column=2, padx=4, pady=2)
global label1
label1 = ttk.Label(frame2, text= 'Enter Animal')
label1.grid(column=2, row=1)
label2 = ttk.Label(guiwindow, text= 'Please enter animal: ', background="#a0d4d6")
label2.grid(column=0, row=1,pady=2,padx=2)
frame1 = Frame(guiwindow, width=250, height = 280, highlightthickness=2, highlightbackground="#111")
frame1.grid(row=2, columnspan=2, padx=10, pady=2)
exitframe1 = Frame(guiwindow, width=100, height = 100, highlightthickness=2, highlightbackground="#111")
exitframe1.grid(row=3, columnspan=2, padx=10, pady=2)
button2 = ttk.Button(frame1, text= 'Top Speed', command= lambda: Animals(input1.get(), 'Top Speed'))
button2.grid(column=0, row=3, pady=2, padx=4)
button3 = ttk.Button(frame1, text= 'Weight', command= lambda: Animals(input1.get(), 'Weight'))
button3.grid(column=0, row=4, pady=2, padx=4)
button4 = ttk.Button(frame1, text= 'Size', command= lambda: Animals(input1.get(), 'Size'))
button4.grid(column=0, row=5, pady=2, padx=4)
button5 = ttk.Button(frame1, text= 'Diet', command= lambda: Animals(input1.get(), 'Diet'))
button5.grid(column=0, row=6, pady=2, padx=4)
button6 = ttk.Button(frame1, text= 'Habitat', command= lambda: Animals(input1.get(), 'Habitat'))
button6.grid(column=0, row=7, pady=2, padx=4)
button7 = ttk.Button(frame1, text= 'Predators', command= lambda: Animals(input1.get(), 'Predators'))
button7.grid(column=1, row=3, pady=2, padx=4)
button8 = ttk.Button(frame1, text= 'Colors', command= lambda: Animals(input1.get(), 'Colour'))
button8.grid(column=1, row=4, pady=2, padx=4)
button9 = ttk.Button(frame1, text= 'Life Span', command= lambda: Animals(input1.get(), 'Life Span'))
button9.grid(column=1, row=5, pady=2, padx=4)
button10 = ttk.Button(frame1, text= 'Prey', command= lambda: Animals(input1.get(), 'Main Prey'))
button10.grid(column=1, row=6, pady=2, padx=4)
button11 = ttk.Button(frame1, text= 'Skin Type', command= lambda: Animals(input1.get(), 'Skin Type'))
button11.grid(column=1, row=7, pady=2, padx=4)
quitbutton = ttk.Button(exitframe1, text="Exit", command= lambda: guiwindow.destroy())
quitbutton.grid(column=0,row=8, pady=4, padx=4)
guiwindow.mainloop()
gui()
AGU()