NameError:名称'filesize_bytes'未定义

问题描述 投票:-1回答:1

我似乎无法解决此错误:

from tkinter import *
root = Tk()
root.config(bg="Green")
root.title("Storage Units - Tkinter")
root.geometry("326x192")

def storage_units():
        if filesize_bytes <1025:
                filesize=round(filesize_bytes,1)
                FileSize_print = Label(root,text="File Size: "+filesize+"Bytes")
        elif filesize_bytes <1048576:
                filesize=round((filesize_bytes/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"KB")
        elif filesize_bytes <1073741824:
                filesize=round((filesize_bytes/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"MB")
        elif filesize_bytes <1099511627776:
                filesize=round((filesize_bytes/1024/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"GB")
        elif filesize_bytes <1125899906842624:
                filesize=round((filesize_bytes/1024/1024/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"TB")
        elif filesize_bytes <1152921504606846976:
                filesize=round((filesize_bytes/1024/1024/1024/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"PB")
        elif filesize_bytes <1180591620717411303424:
                filesize=round((filesize_bytes/1024/1024/1024/1024/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"EB")

        elif filesize_bytes <1208925819614629174706176:
                filesize=round((filesize_bytes/1024/1024/1024/1024/1024/1024/1024),1)
                FileSize_print = Label(root,text="File Size: "+filesize+"ZB")
        else:
                Label(root,text="Your input may be much longer,negative, invalid or in different format")

#Entry
Filesize_in_bytes_entry = Entry(root)
Filesize_in_bytes_entry.pack()

def Filesize_in_bytes_entry_get():
        filesize_bytes = Filesize_in_bytes_entry.get()
        filesize_bytes = int(filesize_bytes)
        storage_units()



Submit_Button_filesize_entry = Button(root,text="Submit",command=Filesize_in_bytes_entry_get)
Submit_Button_filesize_entry.pack()



root.mainloop()

[Tkinter回调回溯中的异常(最近一次通话最近):文件“ C:\ Users \ Muhammad Faizan Raza \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ tkinter__init __。py”,行1883,在[[致电

return self.func(*args) File "w:/Computer-related/Python/noname/storageunits.py", line 43, in Filesize_in_bytes_entry_get storage_units() File "w:/Computer-related/Python/noname/storageunits.py", line 8, in storage_units if filesize_bytes <1025: NameError: name 'filesize_bytes' is not defined
python tkinter tkinter-entry
1个回答
0
投票
因为您必须在函数参数中传递它:

def storage_units(filesize_bytes): if filesize_bytes <1025: ...

拨打电话:

... filesize_bytes =int(filesize_bytes) storage_units(filesize_bytes)

© www.soinside.com 2019 - 2024. All rights reserved.