我正在制作一个 tkinter 应用程序,它可以显示您在一个名为 Scratch 的小型拖放编码网站上是否有消息。但是当我使用 pyinstaller 将它转换为可执行文件并运行它时,它给了我一个错误。我查找了如何修复它,但我得到了一个我不明白的答案,所以请假设我是一个菜鸟程序员,并用最简单的术语给我一个答案。我使用的是 Windows 10 和 python 3.9。
我使用的命令:
pyinstaller --onefile sly.py
错误:
Traceback (most recent call last):
File "requests\packages\urllib3\util.py", line 608, in ssl_wrap_socket
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests\adapters.py", line 309, in send
File "requests\packages\urllib3\connectionpool.py", line 539, in urlopen
File "requests\packages\urllib3\connectionpool.py", line 366, in _make_request
File "http\client.py", line 1253, in request
File "http\client.py", line 1299, in _send_request
File "http\client.py", line 1248, in endheaders
File "http\client.py", line 1008, in _send_output
File "http\client.py", line 948, in send
File "requests\packages\urllib3\connectionpool.py", line 127, in connect
File "requests\packages\urllib3\util.py", line 612, in ssl_wrap_socket
requests.packages.urllib3.exceptions.SSLError: [Errno 2] No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sly.py", line 18, in <module>
File "requests\api.py", line 55, in get
File "requests\api.py", line 44, in request
File "requests\sessions.py", line 357, in request
File "requests\sessions.py", line 480, in send
File "requests\sessions.py", line 480, in <listcomp>
File "requests\sessions.py", line 137, in resolve_redirects
File "requests\sessions.py", line 460, in send
File "requests\adapters.py", line 358, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
这是我的代码:
import time, requests, json, os, threading, webbrowser
from tkinter import *
from tkinter.ttk import *
import pyautogui as pag
def set_interval(func, sec):
def func_wrapper():
set_interval(func, sec)
func()
t = threading.Timer(sec, func_wrapper)
t.daemon = True
t.start()
return t
#starts the session
isError = True
while isError:
usersname = pag.prompt(text='Please enter your username.', title='Scratchly') #pag is pyautogui
req = requests.get("http://api.scratch.mit.edu/users/{}/messages/count/".format(usersname))
jl = json.loads(req.text)
try:
test = jl["code"]
pag.alert(text="Incorrect username")
except:
isError = False
#gui stuffs
root = Tk()
scriptDir = os.getcwd()
scriptDir = scriptDir.replace('\\', '/')
#images
messageImage = PhotoImage(file = "{}/images/message.png".format(scriptDir))
messageRecieved = PhotoImage(file = "{}/images/messagerecieved.png".format(scriptDir))
move = PhotoImage(file = "{}/images/Move.png".format(scriptDir))
togl = True
#define
def Move_On():
global togl
if togl:
root.overrideredirect(0)
togl = False
else:
root.overrideredirect(1)
togl = True
def buttonShow(widget):
widget.pack()
def buttonHide(widget):
try:
widget.pack_forget()
except:
pass
#attributes
root.wm_attributes("-topmost", 1)
root.overrideredirect(1)
#widgets
messageButton = Button(root, image=messageImage, command=lambda: webbrowser.open_new_tab('https://scratch.mit.edu/messages'))
messageRecievedButton = Button(root, image = messageRecieved,command=lambda: webbrowser.open_new_tab('https://scratch.mit.edu/messages'))
moveButton = Button(root, image=move,command=lambda:Move_On()).pack(side=TOP)
#set's up for the buttons
def check_messages():
r = requests.get("http://api.scratch.mit.edu/users/{}/messages/count/".format(usersname))
count = json.loads(r.text)
count = count["count"]
if count > 0:
buttonHide(messageRecievedButton)
buttonShow(messageRecievedButton)
buttonHide(messageButton)
else:
buttonHide(messageButton)
buttonShow(messageButton)
buttonHide(messageRecievedButton)
#main loop
check_messages()
set_interval(check_messages, 10)
root.mainloop()
quit()