Python Forum
tkinter get method is not accepting value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: tkinter get method is not accepting value (/thread-29673.html)



tkinter get method is not accepting value - jagasrik - Sep-15-2020

I am trying a mini project just for my practice purpose, here when i enter the value '1' when i run this program, the option.get() is not accepting the value from 'entry' , because it is not printing "Your existing balance is 10000".
Please note that i have call user_choice function to process to next steps, this is just one part of rest of the project.
If it is accepting it should be printing "Your existing balance is 10000" Please help, thanks in advance.

import tkinter as tk

global balance 

balance= 10000

def user_choice():

    a = (option.get()) #not able to accept input from the entry
    if(a==1):
        print("You existing Balance is ",balance)
    #if(a==2):


    

root1 = tk.Tk()

option = tk.StringVar()  
canvas = tk.Canvas(root1,height=500,width=500)
canvas.pack()
frame = tk.Frame(root1,bg='#80c1ff')
frame.place(relx=0.1,rely=0.1,relwidth=0.8,relheight=0.8)
label = tk.Label(frame,
                 text="|| Enter number 1-4 || \n Please Choose your options",bg="yellow")
label.place(relx=0.15,rely=0.1,relwidth=0.7)
label = tk.Label(frame,
                 text="\n 1- Check saving Balance \n 2- Deposit Funds \n 3- Withdraw Funds \n 4- Transfer Funds ",bg="yellow")
label.place(relx=0.15,rely=0.2,relwidth=0.7)
entry = tk.Entry(root1,bg="gray",textvariable=option) #HERE is the INPUT VALUE Entering
entry.place(relx=0.45,rely=0.43,relwidth=0.09)
button = tk.Button(master=root1, text='OK',bg='purple',activebackground='pink',fg='white',command=user_choice) #Here I am calling the function 
button.place(relx=0.41,rely=0.489,relwidth=0.16) 

root1.mainloop()



RE: tkinter get method is not accepting value - ndc85430 - Sep-15-2020

Please explain what you mean by "it is not accepting the value". Are there errors? Does something not work as expected? More info please!


RE: tkinter get method is not accepting value - jagasrik - Sep-15-2020

(Sep-15-2020, 05:28 PM)ndc85430 Wrote: Please explain what you mean by "it is not accepting the value". Are there errors? Does something not work as expected? More info please!

I have updated my issue, here i mean option.get() method is not accepting the value from 'entry'


RE: tkinter get method is not accepting value - ndc85430 - Sep-15-2020

What type of value does option.get() return? Is it a string?


RE: tkinter get method is not accepting value - jagasrik - Sep-15-2020

(Sep-15-2020, 05:39 PM)ndc85430 Wrote: What type of value does option.get() return? Is it a string?
Thanks a lot , i spent lot of time, i understand it now.

It can be string or int , just i have to convert it either way to work it around, i dint know it would matter so much. Now its working.