1

I have this error:

  text = e1.get()
AttributeError: 'NoneType' object has no attribute 'get'

When I run this code:

from Tkinter import *
import subprocess
import os

master = Tk()
master.geometry("1000x668")
master.title("Menu")
master.configure(background='pale green')
#master.iconbitmap(r"C:\Users\André\Desktop\python\menu.ico")
w = Label(master, text="Abrir", bg="pale green", fg="steel blue", font=("Algerian", 20, "bold"))
w.pack()
w.place(x=100, y=0)

def notepad():
    subprocess.Popen("notepad.exe")

buttonote = Button(master, text="Bloco de notas", wraplength=50, justify=CENTER, padx=2, bg="light sea green", height=2, width=7, command=notepad)
buttonote.pack()
buttonote.place(x=0, y=50)

def regedit():
    subprocess.Popen("regedit.exe")

buttonreg = Button(master, text="Editor de Registo", wraplength=50, justify=CENTER, padx=2, bg="light sea green", height=2, width=7, command=regedit)
buttonreg.pack()
buttonreg.place(x=60, y=50)

def skype():
    subprocess.Popen("skype.exe")

buttonskype = Button(master, text="Skype", bg="light sea green", height=2, width=7, command=skype)
buttonskype.pack()
buttonskype.place(x=120, y=50)

def steam():
    os.startfile("D:\Steam\Steam.exe")

buttonsteam = Button(master, text="Steam", bg="light sea green", height=2, width=7, command=steam)
buttonsteam.pack()
buttonsteam.place(x=178, y=50)

def save():
    text = e1.get()
    SaveFile = open('information.txt','w')
    SaveFile.write(text)
    SaveFile.close()

e1 = Entry(master, width=15)
e1.pack(padx=100,pady=4, ipadx=2)
nome = Label(master, text="Nome?", bg="pale green", fg="steel blue", font=("Arial Black", 12))
nome.pack()
nome.place(x=380, y=0)

buttonsave = Button(master, text="Guardar", bg="light sea green", height=1, width=6, command=save)
buttonsave.pack()
buttonsave.place(x=550, y=0)

mainloop ()

I searched in many sites but can´t find a solution. I would appreciate it if someone would help me fix this.

martineau
  • 119,623
  • 25
  • 170
  • 301
Tubi20
  • 21
  • 2

1 Answers1

0

The problem is with this line:

e1 = Entry(master, width=15).pack(padx=100,pady=4, ipadx=2)

It creates an Entry widget and then immediately calls its pack() method, which doesn't return anything, so e1 gets assigned the value None.

To fix it simply split the line into two separate statements:

e1 = Entry(master, width=15)
e1.pack(padx=100,pady=4, ipadx=2)
martineau
  • 119,623
  • 25
  • 170
  • 301