英文:
My code is not working. Althought GUI is fine, the functions of this application isn't working
问题
这是您的代码中的问题,需要进行修复:
def output():
ip = input_paste.get()
io = input_original.get()
if ip == io:
result_label.config(text="SUCCESS")
else:
result_label.config(text="MALEVOLENT / DON'T RUN")
您需要确保以下更改:
- 修复函数
output()
的参数命名,以避免与输入字段名称冲突。 - 使用
result_label.config
来更改结果标签的文本,以显示相应的消息。
这应该解决您的问题,让您的代码按照您的期望工作。
英文:
Here's My Code:
from tkinter import *
import hashlib
root=Tk()
root.title('iHash Checker')
root.geometry('322x425')
root.configure(background='white')
font='Alef'
primary_color='lightblue'
secondary_color='darkblue'
s1=Label(root,text='_____________________________',font=('Arial'),fg=secondary_color,bg='white').place(x=25,y=50)
logo=Label(root,text='Software Hash Checker',font=(font,18,'bold'),fg=secondary_color,bg='white').place(x=20,y=20)
input_paste=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid').place(x=25,y=80,width=265)
input_paste_label=Label(root,text='Enter The Given Hash In The ZIP File',font=(font,8,'bold'),fg=secondary_color,bg='white').place(x=20,y=106)
input_original=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid').place(x=25,y=130,width=265)
s2=Label(root,text='_____________________________',font=('Arial'),fg=secondary_color,bg='white').place(x=25,y=170)
input_original_label=Label(root,text='Enter The Exact Hash From The Official Site',font=(font,8,'bold'),fg=secondary_color,bg='white').place(x=20,y=160)
"""def output():
ip=input_paste.get()
io=input_original.get()
if ip == io:
result=Label(root,text='Right File',font=font,fg='darkgreen',bg='lightgreen').place(x=25,y=270,width=265)
elif ip != io:
result=Label(root,text='Wrong File',font=font,fg='darkred',bg='red').place(x=25,y=270,width=265)
pass"""
def output():
input_paste = input_paste.get()
input_original = input_original.get()
if input_paste == input_original:
result_label.config(text="Correct!")
else:
result_label.config(text="Wrong!")
btn=Button(root,bg=secondary_color,fg='white',borderwidth=0,relief='flat',font=font,text='Check',command=output).place(x=25,y=190,width=265)
result=Label(root,text='',font=font,fg=secondary_color,bg=primary_color).place(x=25,y=270,width=265)
root.mainloop()
It is throwing an error like this:
B:\Python_Projects\crypto>python gui-hash.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\soumy\anaconda3\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "B:\Python_Projects\crypto\gui-hash.py", line 34, in output
input_paste = input_paste.get()
UnboundLocalError: local variable 'input_paste' referenced before assignment
B:\Python_Projects\crypto>python gui-hash.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\soumy\anaconda3\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "B:\Python_Projects\crypto\gui-hash.py", line 42, in output
ip = input_paste.get()
AttributeError: 'NoneType' object has no attribute 'get'
Please find the error and slove. mostly from line 33 to 44.
Using libarieshashlib
and tkinter
Running conda, python3 latest, pip
i want to see that when i write the data in two text input boxes, it will fetch the inputs and then check wether the first one matches with other. If so, then it will show success. If not then it will show malecious / don't run.
like this:
MY IMAGIINATION:
if INPUT1 is equals to INPUT 2
then show "SUCCESS" in the box
else show "MALECIOUS / DON'T RUN" in the box
答案1
得分: 2
你有两个问题。
首先,你将Entry()和place()连在一起:
input_paste=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid').place(x=25,y=80,width=265)
因此,input_paste
被赋值为.place()
的返回值,即None。
改为先调用Entry
,然后再调用place()
:
input_paste=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid')
input_paste.place(x=25,y=80,width=265)
其次,在output()
函数中,你试图完全替换input_paste
变量,这样它将不再是一个Entry:
input_paste = input_paste.get()
在左边使用其他变量名。将其命名为paste_text
或其他名称。
英文:
You have two problems.
First, you're chaining Entry() and place() together all in one step:
input_paste=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid').place(x=25,y=80,width=265)
Because of this, input_paste
is assigned to the return value of .place()
, which is None.
Instead, call Entry
as a first step, then call place()
afterwards:
input_paste=Entry(root,font=('Arial'),fg=secondary_color,bg='white',borderwidth=2,relief='solid')
input_paste.place(x=25,y=80,width=265)
Second, in the output()
function, you're trying to completely replace the input_paste
variable, so it would no longer be an Entry at all:
input_paste = input_paste.get()
Use some other variable name on the left. Call it paste_text
or something.
答案2
得分: -1
在你的函数的第一行:
input_paste = input_paste.get()
因为这是一个赋值语句,它将input_paste
视为局部变量。
是的,你在全局范围内有另一个input_paste
,但只有在声明你要使用全局版本时才能访问它(或者只将其用作右值):
global input_paste
input_paste = input_paste.get()
...
这可能不是你想要的,因为它正在用局部变量覆盖全局变量,而你可能想要在局部使用它。可能需要将局部变量命名为不同的名称(如注释掉的版本中所示):
ip = input_paste.get()
...
(还要修复其他人指出的其他问题,一旦它可以解析代码,这些问题将成为问题)
英文:
On the first line of your function:
input_paste = input_paste.get()
Because this is an assignment, it treats input_paste
as a local variable.
Yes, you have another input_paste
in global scope, but you can only access it if you declare you are using the global version (or only use it as a r-value):
def output():
global input_paste
input_paste = input_paste.get()
...
This is probably not what you want, because it is overwritting the global variable with something you may want to use locally. It is probably required to name the local variables something different (as in the commented out version)
def output():
ip = input_paste.get()
...
(and also, fix the other issues people pointed out, which will be a problem once it can even parse the code)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论