-1

Hi im trying to build a notification app with python and Tkinter, i want to access the text of a Label from my function with .get() but it seems not to work.

from tkinter import *
from tkinter import messagebox
import time
from plyer import notification

gui = Tk()
gui.geometry('500x500')
gui.title('Notifier App')

def createNotification():
    if titleEntry != '' and messageText != '' and whenToDisplayEntry != '':
        get_title = titleEntry.get()
        get_message = messageText.get()
        get_time = int(float(whenToDisplayEntry.get()))
        messagebox.showinfo('Notification', 'Successfully created a notification!')
        time.sleep(get_time * 60)
        notification.notify(title=get_title, message=get_message, timeoout=10)

    else:
        messagebox.showerror('Error', 'Must fill all fields.')

bigLogo = Label(gui, text = 'Make a notification', font = ('Arial', 30)).place(x = 150,y = 1)
title = Label(gui,text='Title of notification:',font=('Arial', 15)).place(x=1,y=100)
titleEntry = Entry(gui, width='20',font=('Arial', 15)).place(x=170,y=100)
message = Label(gui,text='Message:',font=('Arial', 15)).place(x=1,y=150)
messageText = Text(gui, width='20',height='7',font=('Arial', 15)).place(x=95,y=150)
whenToDisplay = Label(gui,text='When to display(in minutes):', font=('Arial', 15)).place(x=1,y=350)
whenToDisplayEntry = Entry(gui, width='10',font=('Arial', 15)).place(x=255,y=350)
createButton = Button(gui,text='Create a notification!',command=createNotification).place(x=180,y=450)

gui.mainloop()
  • Please, always add the traceback of the error message. – Demi-Lune Sep 05 '22 at 07:59
  • @Demi-Lune the error: Exception in Tkinter callback Traceback (most recent call last): File "D:\Python\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "D:\PyCharm Community Edition 2022.2\Projects\main.py", line 12, in createNotification get_title = titleEntry.get() AttributeError: 'NoneType' object has no attribute 'get' – Alex Gurinovich Sep 05 '22 at 08:00
  • I mean, add the Error in your question (it is unreadable in comments). And also, the Traceback gives you all the info you need to find the error. – Demi-Lune Sep 05 '22 at 08:03
  • 1
    See this post : https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name to get more information on your problem. – sramazoth Sep 05 '22 at 08:06

1 Answers1

0

By chaining:

x = Entry(...).place(...)

x takes the return value of the function place, which is None.

Split your command in 2 lines:

titleEntry = Entry(gui, width='20',font=('Arial', 15))
titleEntry.place(x=170,y=100)
Demi-Lune
  • 1,868
  • 2
  • 15
  • 26