My code is not working. Althought GUI is fine, the functions of this application isn't working

86 Views Asked by At

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
2

There are 2 best solutions below

0
John Gordon On

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.

4
Geoduck On

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)