为什么拆分方法停止使用TKINTER?
每当我使用concped = first_word.split()
行运行此代码时,我会收到一个错误(窗口立即关闭)。
import tkinter as tk
win = tk.Tk()
win.title("Conversation")
win.iconbitmap("cake.ico")
win.geometry("600x700")
#Lists
Hellos = ["greetings", 'hello', 'greetings', 'hi']
gday = ['good', 'great', 'incredible', 'not bad', 'okay']
bday = ['bad', 'awful', 'not the best', 'terrible']
fw_label = tk.Label(win, text="Hello user, it's nice to meet you.")
fw_label.pack()
first_word = tk.Entry()
first_word.pack()
chopped = first_word.split()
但是,当我更改行first_word = tk.entry()
first_word =“ a normal String” 时,拆分方法突出显示,当我悬停时,它给出了其描述, ````first_word = tk.entry()''没有发生。
使用OpenCV之类的库时,我遇到了这个问题,我可以知道是什么原因导致它不起作用?
Whenever I run this code with the chopped = first_word.split()
line I get an error (the window closes instantly).
import tkinter as tk
win = tk.Tk()
win.title("Conversation")
win.iconbitmap("cake.ico")
win.geometry("600x700")
#Lists
Hellos = ["greetings", 'hello', 'greetings', 'hi']
gday = ['good', 'great', 'incredible', 'not bad', 'okay']
bday = ['bad', 'awful', 'not the best', 'terrible']
fw_label = tk.Label(win, text="Hello user, it's nice to meet you.")
fw_label.pack()
first_word = tk.Entry()
first_word.pack()
chopped = first_word.split()
But when I change the line first_word = tk.Entry()
to first_word="A normal string"
, the split method highlights and when I hover it it gives its description, which wasn't happening with ```first_word = tk.Entry()``.
I've ran into this problem when using libraries like opencv, may I know what's causing it not to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案很简单。按下提交按钮时,您必须调用一个函数。语句
conced = first_word.get()。split()
应该在该功能内部。到了错误部分,这是因为
first_word
是一个entribute
object object split> split()。拆分方法仅适用于字符串。要以字符串的形式将文本输入到条目小部件中,您需要使用
get()
方法...因此,您使用
get()获取条目文本
方法,然后将其分开注意:语句
chopped = first_word.get()。split()
应该在函数内部,因为如果其外部,它将在其外部执行创建条目小部件并使用get()
将导致空值,因为该条目当时不包含任何内容The solution is simple. You have to make a function to be called while pressing the submit button. And the statement
chopped = first_word.get().split()
should be inside that function.Coming to the error part, it was because
first_word
is a tkinterentry
object without any attributesplit()
.The split method works only for strings. To get the text entered into the entry widget in form of string, you need to use the
get()
method...So, you get the text of the entry using the
get()
method and then split itNote : The statement
chopped = first_word.get().split()
should be inside the function because if its outside it, it would be executed at the time of the creation of the entry widget and usingget()
there would result in an empty value as the entry doesn't contain anything at that point也许这可以
改变
为
Maybe this could work
Change
to
由于声誉较低,我无法回答我对您的最后一个问题的评论。
https://www.shapedivider.app/
在这里您可以轻松地制作所需的曲线并将代码嵌入到项目中。我经常使用。I'm unable to reply my comment on your last question because of my low reputation.
https://www.shapedivider.app/
here you would easily make the curves you want and embed the code to your project. I use this often.