I am trying to build an app using Tkinter and Pywhatkit , the functionality is that you enter the phone no.,message and time ( in minutes,seconds).I did the front end but the back end is a little complicated , here's the code:
import tkinter as tk
import pywhatkit
root = tk.Tk()
def Function():
n=Entry1.get()
m=Entry2.get()
l=Entry3.get()
i=Entry4.get()
pywhatkit.sendwhatmsg("+91n","m",l,i)
Label1 = tk.Label(root, text="Mscheduler",bg='#99e6ff',font="Verdana 34")
Label1.grid(columnspan=1)
Label2= tk.Label(root,text="Enter phone no.",bg="#c2f0c2",font="verdana 22")
Label2.grid(row=2 , column=0)
Entry1=tk.Entry(root,bg="#ffe6b3",font="verdana 22")
Entry1.grid(row=2, column=1)
Label3= tk.Label(root,text="Enter message.",bg="#c2f0c2",font="verdana 22")
Label3.grid(row=3 , column=0)
Entry2=tk.Entry(root,bg="#ffe6b3",font="verdana 22")
Entry2.grid(row=3, column=1)
Label4= tk.Label(root,text="Enter time.",bg="#c2f0c2",font="verdana 22")
Label4.grid(row=4 , column=0)
Entry3=tk.Entry(root,bg="#ffe6b3",font="verdana 22")
Entry3.grid(row=4, column=1)
Entry4=tk.Entry(root,bg="#ffe6b3",font="verdana 22")
Entry4.grid(row=4, column=2)
Button1=tk.Button(root, text="send", bg="#d1d1e0", font="verdana 16", command=Function)
Button1.grid(row=5, column=1)
root.mainloop()
I went to the pywhatkit
docs and looked at the function you are trying to use. It wants a phone number in string format, a message in string format, an hour in int format, and a minute in int format.
I renamed all of your Entry
widgets to 'phone', 'message', 'hour' and 'minute', because that's what they are. I then changed your 'message' Entry
to a Text
widget. I was thinking that the 15 or so characters that you were allowing for a message, isn't enough to say anything, at all. I then renamed your Function
function to send
, because that's what it does.
Finally, I set the arguments in the sendwhatmsg
call to a phone number in string format, a message in string format, an hour in int format, and a minute in int format, because that's exactly what the docs said to do.
import tkinter as tk
import pywhatkit
root = tk.Tk()
root.grid_columnconfigure(2, weight=1)
def send():
#print(f'+91{phone.get()}', message.get('1.0', 'end-1c'), int(hour.get()), int(minute.get()))
pywhatkit.sendwhatmsg(f'+91{phone.get()}', message.get('1.0', 'end-1c'), int(hour.get()), int(minute.get()))
#title
tk.Label(root, text="Mscheduler", bg='#99e6ff', font="Verdana 34").grid(columnspan=3, sticky='w')
#phone
tk.Label(root,text="Phone: ", bg="#c2f0c2", font="verdana 22").grid(row=1, column=0, sticky='w')
phone = tk.Entry(root, bg="#ffe6b3", font="verdana 22", width=10)
phone.grid(row=1, column=1, sticky='w', columnspan=2)
#message
tk.Label(root,text="Message: ", bg="#c2f0c2", font="verdana 22").grid(row=2, column=0, sticky='nw')
message=tk.Text(root, bg="#ffe6b3", font="verdana 22", height=4, width=32)
message.grid(row=2, column=1, sticky='w', columnspan=2)
#time
tk.Label(root,text="Time HH:MM", bg="#c2f0c2", font="verdana 22").grid(row=3, column=0, sticky='w')
#hour
hour=tk.Entry(root, bg="#ffe6b3", font="verdana 22", width=2)
hour.grid(row=3, column=1, sticky='w')
#minute
minute=tk.Entry(root, bg="#ffe6b3", font="verdana 22", width=2)
minute.grid(row=3, column=2, sticky='w')
#send button
tk.Button(root, text="send", bg="#d1d1e0", font="verdana 16", command=send).grid(row=4, column=2, sticky='e')
root.mainloop()