[Python] Pydroid Tkinter Not Reassigning

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have this Python Tkinter code right here:

    from tkinter.filedialog import *
    import tkinter as tk

    class App(tk.Tk):
    def __init__(self):
    super().__init__()

    self.apptitle = "TODO.py"

    #...other code

    self.openfile = None
    self.savefile = None
    self.currentfile = None
    self.filetype = [("Text File", "*.txt"), ("Markdown File", "*.md")]

    #...other code

    def filemenu_save(self):
    if self.currentfile is None:
    self.savefile = asksaveasfile(filetypes=self.filetype, defaultextension=self.filetype)
    try:
    self.currentcontent = self.textbox.get("1.0", tk.END).rstrip("\n")
    with open(self.savefile.name, "w", encoding="utf-8-sig") as f:
    f.write(self.currentcontent)
    self.currentfile = self.savefile
    self.title(self.apptitle + " - " + self.savefile.name)
    except IOError as e:
    print("An error occurred while writing to the file:", e)
    else:
    try:
    self.currentcontent = self.textbox.get("1.0", tk.END).rstrip("\n")
    with open(self.currentfile.name, "w", encoding="utf-8-sig") as f:
    f.write(self.currentcontent)
    self.currentfile = self.currentfile
    except IOError as e:
    print("An error occurred while writing to the file:", e)

    #...other code


    That takes the content of a tk.Text() and writes it to the saved file. But, even tho this code does work on the normal Python, this didn't work in Pydroid.

    It gives me this error:

    Exception in Tkinter callback
    Traceback (most recent call last):
    File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.13/tkinter/__init__.py", line 2071, in __call__
    return self.func(*args)
    ~~~~~~~~~^^^^^^^
    File "/storage/emulated/0/GitHub Mobile Stuff/TODO.py/TODO.py", line 149, in filemenu_save
    with open(self.savefile.name, "w", encoding="utf-8-sig") as f:
    ^^^^^^^^^^^^^^^^^^
    AttributeError: 'NoneType' object has no attribute 'name'


    Even tho it should just return the file as an object and then go with the rest of the code. I'm not sure why it's not reassigning it in Pydroid.

    (Also I'm not that good with Python yet, there are things that I don't know of.)

    Continue reading...

Compartilhe esta Página