Tkinkter no accepting country code properly - python

I am making this college project using tkinter GUI and pywhatkit. It's showing Country code missing even if I put it (with symbol).
My code:
from tkinter import *
import pywhatkit as kit
import tkinter.messagebox as tmsg
root = Tk()
root.title("Whatsapp Auto Message Scheduler")
p_num = str(Label(root, text = 'Enter the phone number(with Country code):').grid(row = 0))
msg = Label(root, text = 'The message:').grid(row = 1)
h = Label(root, text = 'Timing(hour, as per 24hr clock):').grid(row = 2)
m = Label(root,text = 'Timing(minute):').grid(row = 3)
e1 = Entry(root)
e2 = Entry(root)
e3 = Entry(root)
e4 = Entry(root)
e1.grid(row = 0, column = 1)
e2.grid(row = 1, column = 1)
e3.grid(row = 2, column = 1)
e4.grid(row = 3, column = 1)
def pywhatkit():
p = kit.sendwhatmsg(p_num, msg, h, m)
tmsg.showinfo("Whatsapp Auto Mesage Scheduler","Response Submitted!")
return p
B = Button(root, text = 'Submit', command = pywhatkit)
B.grid(row=4,column=1)
root.mainloop()
The error it's showing:

There are a couple of problems. Have you actually checked to see what p_num = str(Label(...)) is? Let's try it in the shell:
>>> import tkinter
>>> str(tkinter.Label(text="Hello world").grid(row=0))
'None'
>>>
I won't get really into it, but the correct way of getting a user's entry is by invoking .get() on the associated entry widget:
Label(root, text = 'Enter the phone number(with Country code):').grid(row = 0)
Label(root, text = 'The message:').grid(row = 1)
Label(root, text = 'Timing(hour, as per 24hr clock):').grid(row = 2)
Label(root, text = 'Timing(minute):').grid(row = 3)
phone_number_entry = Entry(root)
message_entry = Entry(root)
hour_entry = Entry(root)
minute_entry = Entry(root)
phone_number_entry.grid(row = 0, column = 1)
message_entry.grid(row = 1, column = 1)
hour_entry.grid(row = 2, column = 1)
minute_entry.grid(row = 3, column = 1)
def pywhatkit():
phone_number = phone_number_entry.get()
message = message_entry.get()
hour = int(hour_entry.get())
minute = int(minute_entry.get())
kit.sendwhatmsg(phone_number, message, hour, minute)
tmsg.showinfo("Whatsapp Auto Mesage Scheduler","Response Submitted!")

Related

Cant use Tkinter button more than once

im kinda new to tkinter and while working on a school project ive stumbbled a problem, the button i use to change a label cant be used more than once.
here is the full code:
from tkinter import *
import random, time
dic = {}
def pDic(dic):
print(dic)
def add(dic):
org = orgEntry.get()
tran = tranEntry.get()
dic[org] = tran
tranEntry.delete(0,END)
orgEntry.delete(0,END)
return dic
def clear():
labOrg.grid_remove()
labTran.grid_remove()
orgEntry.grid_remove()
tranEntry.grid_remove()
save.grid_remove()
printDic.grid_remove()
train.grid_remove()
def pMain(dic):
global practiceBtn
clear()
i=0
kList = list(dic)
random.shuffle(kList)
practiceEntry = Entry(app)
practiceEntry.grid(row = 1 , column = 1)
labPractice = Label(app, text = "Enter translation for: " + kList[i] )
labPractice.grid(row = 0 , column = 1, padx = 200)
practiceBtn = Button(app, text = "Check", command = lambda : pLoop(i,kList,labPractice,dic,practiceEntry.get()))
practiceBtn.grid(row = 2 , column = 1)
def pLoop(i,kList, labPractice, dic ,entered):
if entered== dic[kList[i]]:
i+=1
next(i,kList,labPractice)
def next(i,kList,labPractice):
labPractice.grid_remove()
labPractice = Label(app, text = "Enter translation for: " + kList[i] )
labPractice.grid(row = 0 , column = 1, padx = 200)
app = Tk()
app.geometry('600x450+1000+60')
app.title("Dictionary")
labOrg = Label(app, text = "Enter Word")
labOrg.grid()
orgEntry = Entry(app)
orgEntry.grid(padx = 20)
labTran = Label(app, text = "Enter Translation")
labTran.grid(row = 0, column = 1, padx = 70)
tranEntry = Entry(app)
tranEntry.grid(row = 1, column = 1, padx = 70)
save = Button(app, text = "Save to dictionary", command = lambda : add(dic))
save.grid(row = 2 ,column = 1,columnspan = 1, pady=10, padx=50)
printDic = Button(app, text = "print dictionary", command = lambda : pDic(dic))
printDic.grid()
train = Button(app, text = "Train", command = lambda : pMain(dic))
train.grid(row = 2, pady = 20, padx = 50)
app.mainloop()
right now its kinda messy (and unfinished :p)but id be thankfull if you can run my code and tell me why the practiceBtn is not working.
the point is to get a dictionary as an input when keys are words and the values are the translation, then give the user a way to practice those words by cycling through all of them.

How do I use grid system on entry widget affected by .get()

my code:
import tkinter as tk
from tkinter import *
truth = ""
us = ""
uss = ""
root = Tk()
s = Label(root, text = ".")
s.grid(row = 1, column = 1)
wel = Label(root, text = "whats your email")
wel.grid(row = 1, column = 5)
inp = Entry(root).get()
inp.grid(row = 3, column = 5)
def callback():
us = inp[:inp.index("#")]
uss = inp[inp.index("#")+1:]
truth =us, " is username, and ", uss,"is domain"
print(truth)
sub = Button(root, text = "submit", command = callback)
sub.grid(row = 5, column = 5)
final = Label(root, textvariable = truth)
final.grid(row = 5, column = 6)
root.mainloop()
Then I get an error message:
'str' object has no attribute 'grid'
How do I use grid system on entry widget affected by .get()?

Tkinter get() function is not returning anything [duplicate]

This question already has answers here:
Why is my Button's command executed immediately when I create the Button, and not when I click it? [duplicate]
(5 answers)
Closed 3 years ago.
I am trying to write a program using a tkinter GUI to calculate a few things. My get() function isn't working and I'm not sure why
from tkinter import *
from math import *
root = Tk()
v = 0
l = 0
w = 0
t1 = 0
t0 = 0
label1 = Label(root, text = "Enter value for length (mm) :").grid(columnspan = 2, sticky = "E")
length = Entry(root).grid(row = 0, column = 2)
label2 = Label(root, text = "Enter value for volume (mm^2) :").grid(columnspan = 2, sticky = "E")
volume = Entry(root).grid(row = 1, column = 2)
label3 = Label(root, text = "Enter value for the thickness of the cylinder (mm) :").grid(columnspan = 2, sticky = "E")
thickness = Entry(root).grid(row = 2, column = 2)
label4 = Label(root, text = "Enter value for starting temperature (K) :").grid(columnspan = 2, sticky = "E")
st_T = Entry(root).grid(row = 3, column = 2)
label5 = Label(root, text = "Enter value for finishing temperature (K) :").grid(columnspan = 2, sticky = "E")
end_T = Entry(root).grid(row = 4, column = 2)
def save():
v = volume.get()
l = length.get()
w = thickness.get()
t0 = st_T.get()
t1 = end_T.get()
global values
values = [v, l, w, t1, t0]
answer = StringVar()
labelans = Label(root, textvariable = answer).grid(columnspan = 3,)
answer.set("Answer = ")
def area_circle():
global answer
answer = v / l
print(answer)
Button(root, text = "Submit", command = save()).grid(row = 6, column = 0)
root.mainloop()
Obviously there are variables i'm not using yet but im trying to get the first part right first.
For v the error displayed is:
Message='NoneType' object has no attribute 'get'
The Grid geometry manager puts the widgets in a 2-dimensional table.
The master widget is split into a number of rows and columns, and each
“cell” in the resulting table can hold a widget.
What is important Grid() is returning NoneValue
if you are doing like:
length = Entry(root).grid(row = 0, column = 2)
in your variable length you will have NoneValue
you should do it like :
length = Entry(root)
length.grid(row = 0, column = 2)
your code:
label1 = Label(root, text = "Enter value for length (mm) :")
label1.grid(columnspan = 2, sticky = "E")
length = Entry(root)
length.grid(row = 0, column = 2)
label2 = Label(root, text = "Enter value for volume (mm^2) :")
label2.grid(columnspan = 2, sticky = "E")
volume = Entry(root)
volume.grid(row = 1, column = 2)
label3 = Label(root, text = "Enter value for the thickness of the cylinder (mm) :")
label3.grid(columnspan = 2, sticky = "E")
thickness = Entry(root)
thickness.grid(row = 2, column = 2)
label4 = Label(root, text = "Enter value for starting temperature (K) :")
label4.grid(columnspan = 2, sticky = "E")
st_T = Entry(root)
st_T.grid(row = 3, column = 2)
label5 = Label(root, text = "Enter value for finishing temperature (K) :")
label5.grid(columnspan = 2, sticky = "E")
end_T = Entry(root)
end_T.grid(row = 4, column = 2)
def save():
v = volume.get()
l = length.get()
w = thickness.get()
t0 = st_T.get()
t1 = end_T.get()
global values
values = [v, l, w, t1, t0]
answer = StringVar()
labelans = Label(root, textvariable = answer).grid(columnspan = 3,)
answer.set("Answer = ")
def area_circle():
global answer
answer = v / l
print(answer)
Button(root, text = "Submit", command = save()).grid(row = 6, column = 0)
root.mainloop()
output:
The command argument should be a callback, not the actual call:
Button(root, text="Submit", command=save).grid(row=6, column=0)

Is it possible to add mulitple entries to one line in a listbox?

Right now you can add the data to the listbox, thanks to the stack overflow communinity, i'm not sure if it is possible to have all entries on the same line in the listbox
I know if i use one entry box everything will be on one line
from tkinter import *
from tkinter import messagebox
def add_task():
task = name_input.get()
start_dte = start_date_input.get()
due_dte = due_date_input.get()
pri = pri_input.get()
stat = status_input.get()
# end
listbox.insert(1, task)
listbox.insert(1, start_dte)
listbox.insert(1, due_dte)
listbox.insert(1, pri)
listbox.insert(1, stat)
def clear_all():
listbox.delete(0,END)
root = Tk()
root.title("Todo list") # title of the application
#root.geometry("900x400") # size of the application
titlelbl=Label(root, text = 'Welcome to your To-do-list', font='Times 30 bold').grid(row=0, column=5)#pack(),place(x = 25, y = 30)
name_input = StringVar()
start_date_input = StringVar()
due_date_input = StringVar()
pri_input = StringVar()
status_input = StringVar()
Label(root, text = "Name").grid(row = 6, column = 4)#pack()
name = Entry(root, textvariable = name_input)
name.grid(row = 7, column = 4)#pack()
Label(root, text = "Start date").grid(row = 6, column = 5)#pack()
start_date = Entry(root, textvariable = start_date_input)
start_date.grid(row = 7, column = 5)#pack()
Label(root, text = "Due date").grid(row = 6, column = 6)#pack()
due_date = Entry(root, textvariable = due_date_input).grid(row = 7, column = 6)#pack()
Label(root, text = "Priority").grid(row = 6, column = 7)#pack()
priority = Entry(root, textvariable = pri_input)
priority.grid(row = 7, column = 7)#pack()
Label(root, text = "Status").grid(row = 6, column = 8)#pack()
status = Entry(root, textvariable = status_input)
status.grid(row = 7, column = 8)#pack()
add_btn = Button(root, text = 'Add', width = 10, height = 3, command = add_task)
add_btn.grid(row = 9, column= 7)#pack()#place(x = 15, y = 50)
listbox = Listbox(root,font=('', 12), width = 60, height = 10)
listbox.grid(row = 3, column = 5)#pack()
listbox.insert(1, 'Name Start date Due Date Priority Status')
Button(root, text = 'Clear',width = 10, height = 3, command = clear_all).grid(row =9, column =10)
root.mainloop()
The expected result is for the user to enter the data from the entry boxes into the lisbox as one line.
Instead because they all have it as insert at 1 they go underneath each other
One way you could achieve this is by making your entry a string first then inserting.
def add_task():
task = name_input.get()
start_dte = start_date_input.get()
due_dte = due_date_input.get()
pri = pri_input.get()
stat = status_input.get()
test_string = task+" "+start_dte+" "+due_dte+" "+pri+" "+stat
listbox.insert(1,test_string)
just like you made your headers in your list box by making it a string.

How do i make a continue button? Python, tkinter

I want to make a button in my widget that when I press it, it proceeds to the next lines of code, and closes the existing widget of where the button is.
from tkinter import *
root = Tk()
Label(root, text = "Childs First name").grid(row = 0, sticky = W)
Label(root, text = "Childs Surname").grid(row = 1, sticky = W)
Label(root, text = "Childs Year of Birth").grid(row = 2, sticky = W)
Label(root, text = "Childs Month of Birth").grid(row = 3, sticky = W)
Label(root, text = "Childs Day of Birth").grid(row = 4, sticky = W)
Fname = Entry(root)
Sname = Entry(root)
x = Entry(root)
y = Entry(root)
z = Entry(root)
Fname.grid(row = 0, column = 1)
Sname.grid(row = 1, column = 1)
x.grid(row = 3, column = 1)
y.grid(row = 2, column = 1)
z.grid(row = 4, column = 1)
button1 = Button(root, text = "Quit", command = root.quit, bg = "Grey", fg = "White", width = 12).grid(row = 5, column = 0, sticky = W)
def save():
Fname_value = Fname.get()
Sname_value = Sname.get()
x_value = x.get()
y_value = y.get()
z_value = z.get()
save()
mainloop()
Sorry for this late answer. To make a 'continue' button:
continue_button = tk.Button(frame,text='continue',command=func)
continue_button.config(width=width_continue_button)
# set the coordinates as you want. here 2,6 for the example
continue_button.grid(row=2,column=6,padx=width_continue_grid)
then you have to write the function 'func' to fulfill your needs.
hope this helps

Categories