- 已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
4小时前关门了。
Improve this question
所以我试着做了一个助手来找到我们想要的有用的网站,就像如果我们写Python教程,它会找到我们一些网站,我们可以得到我们想要的(Python教程现在BC我们分配他们)
我第一次尝试这个
from tkinter import *
from tkinter import ttk
from googlesearch import search
import pyttsx3
engine = pyttsx3.init()
win= Tk()
win.geometry("750x250")
def display_text():
global entry
string = entry.get()
engine.say('This site can help you')
engine.runAndWait()
for j in search(string, stop=1):
label.configure(text = j)
def open_url(url):
webbrowser.open_new_tab(url)
lbll = Label(text = 'Welcome to DID Helper!')
lbll.pack()
lbl = Label(win, text = 'Find out\n any theme you want')
lbl.pack()
label=Label(win, text="", font=("Courier 22 bold"), cursor = 'hand2')
label.pack()
label.bind("<Button-1>", lambda e:open_url(url))
url = label
entry= Entry(win, width= 40)
entry.focus_set()
entry.pack()
ttk.Button(win, text= "Find",width= 20, command = display_text).pack(pady = 4)
出现此错误
File "C:\Users\Asus\Desktop\NEW www.example.com",line 30,in label. bind("",lambda e:open_url(url))^^^^^^^^^^^File "C:\Users\Asus\Desktop\NEW www.example.com",line 20,in open_url www.example.com_new_tab(url)^^^^^^^^^^^^Name Error:AI.py 文件“C:\Users\Asus\AppData\Local\Programs\Python\Python311\Lib\tkinter_* init _. py”,第1948行,在callreturn self. func( args)中^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AI.py", line 20, in open_url webbrowser.open_new_tab(url) ^^^^^^^^^^ NameError: name 'webbrowser' is not defined Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Asus\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py", line 1948, incallreturn self.func(*args) ^^^^^^^^^^^^^^^^ i really cant understand what is wrong but i hope u will help me
1条答案
按热度按时间ufj5ltwl1#
在
open_url
函数中,您调用webbrowser.open_new_tab(url)
,而没有导入webbrowser
模块。将此行添加到导入语句中:
这个模块是预装的,所以你不需要使用
pip
来安装它。