Python Forum
tkinter get function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter get function
#1
Hi,

I have the below code. What i want it to do is that when the button is clicked it outputs what is in the two entry boxes. However when I press the button nothing happens, what am I doing wrong?

import tkinter as tk

window = tk.Tk()


label = tk.Label(text="Type Below", fg="white", bg="black", width=10, height=5)
label.grid(row=0)

user_label=tk.Label(text="Username", fg= "white", bg="black", width=25, height=5)
user_label.grid(row=1)
pass_label=tk.Label(text="Password", fg= "white", bg="black", width=25, height=5)
pass_label.grid(row=2)

username_1=tk.Entry(fg="blue", bg="green", width=50)
username_1.grid(row=1, column=1)
password_1=tk.Entry(fg="blue", bg="green", width=50)
password_1.grid(row=2, column=1)

def clicked():
    username=username_1.get()
    password=password_1.get()
    print (username)
    print(password)

button=tk.Button(text="Click", fg="white", bg="blue", width=25, height=5, command="clicked")
button.grid(row=3)

window.mainloop()
Many Thanks,

finndude
Reply
#2
On line 25, should you really be passing the string "clicked", or your function?
Reply
#3
(Mar-02-2021, 03:51 PM)ndc85430 Wrote: On line 25, should you really be passing the string "clicked", or your function?

MEant to be the function, a silly mistake by me. Everything is now working, thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Tkinter inside function not working Ensaimadeta 5 4,865 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,744 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,740 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Creating a function interrupt button tkinter AnotherSam 2 5,421 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 4,921 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter -- after() method and return from function -- (python 3) Nick_tkinter 12 7,240 Feb-20-2021, 10:26 PM
Last Post: Nick_tkinter
  function in new window (tkinter) Dale22 7 4,968 Nov-24-2020, 11:28 PM
Last Post: Dale22
Star [Tkinter] How to perform math function in different page of Tkinter GUI ravaru 2 4,519 Oct-23-2020, 05:46 PM
Last Post: deanhystad
  Call local variable of previous function from another function with Python3 & tkinter Hannibal 5 4,360 Oct-12-2020, 09:16 PM
Last Post: deanhystad
  tkinter get method is not accepting value when called by function jagasrik 1 2,496 Sep-16-2020, 05:28 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020