返回 self.func(*args) python Tinkter

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

所以每次我尝试“处理”保存文件时它都会吐出:

>  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "d:\source\BBSaveEditorFix\app.py", line 291, in _process_data_user
    self.data, self.user = process_user(self.file_location)
    ^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable bool object

这是第 291 行的代码:

    def _load_all_gems(self):
        if self.gems is None:
            messagebox.showwarning("File not loaded!", "You can not reset all modifications since no file is loaded")
            return
        self.combobox_all_gems['values'] = [list(gem.get_original_stats())[0] for gem in self.gems]

    def _set_original_gem_stats(self, e=None):
        if e is not None:
            for gem in self.gems:
                if list(gem.get_original_stats())[0] == e.widget.get():
                    self.selected_gem = gem
        for i, (gem_menu, value) in enumerate(zip(self.all_gem_menu, list(self.selected_gem.get_original_stats()))):
            if i > 2:
                gem_menu.set(value)
            else:
                gem_menu.config(state="normal")
                gem_menu.delete(0, END)
                gem_menu.insert(INSERT, value)
                gem_menu.config(state="disabled")

    def _process_data_user(self):
        if self.file_location is None:
            messagebox.showwarning("User not loaded!", "No file selected")
        self.data, self.user = process_user(self.file_location)
        self._set_original_users_stats()

    def _process_data_gems(self):
        if self.file_location is None:
            messagebox.showwarning("File not loaded!", "No file selected")
        self.data, self.gems = process_gems(self.file_location)
        self._load_all_gems()

    def _open_file_selection(self):
        self.file_location = filedialog.askopenfilename(initialdir="./")
        self.file_loc_ent.config(state="normal")
        self.file_loc_ent.delete(0, END)
        self.file_loc_ent.insert(INSERT, self.file_location)
        self.file_loc_ent.config(state="disabled")

这是process_user代码:

def proecess_user(filename: str):
    data = None
    with open(filename, "rb") as f:
        data = f.read()
    hexdata = binascii.hexlify(data)
    if not data.startswith(b"41000000000000"):
        return False
    return data, extract_user_info(data) 


def process_gems(filename: str):
    data = None
    with open(filename, "rb") as f:
        data = f.read()
    data = binascii.hexlify(data)
    if not data.startswith(b"41000000000000"):
        return False
    return data, extract_gems(data)
python-3.x data-analysis
1个回答
0
投票

这要求函数返回两个值的序列:

self.data, self.user = process_user(self.file_location)

但是在函数中,有这样的:

if not data.startswith(b"41000000000000"):
    return False

...这会导致错误。

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