Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable not defined
#2
Prints in the console for me. If you want it to print in a label then you will have to let it know to.
from tkinter import *
root = Tk()

def ans1():
    AnswerSelected = 44
    label['text'] = AnswerSelected
    print (AnswerSelected)

label = Label(root)
label.grid(column=5, row=4)

Answer1 =Button(root,text="Click me", padx=50, pady=50, bg ="red", command =ans1)
Answer1.grid( row =5, column = 5)
root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Variable not defined - by Heyjoe - Jul-10-2020, 01:15 AM
RE: Variable not defined - by menator01 - Jul-10-2020, 01:30 AM
RE: Variable not defined - by Heyjoe - Jul-10-2020, 11:42 AM
RE: Variable not defined - by ndc85430 - Jul-10-2020, 11:54 AM
RE: Variable not defined - by Heyjoe - Jul-10-2020, 11:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 302 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 605 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,342 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,150 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Function will not return variable that I think is defined Oldman45 6 3,549 Aug-18-2020, 08:50 PM
Last Post: deanhystad
  How to assign a module to a variable even if it's not defined? mandaxyz 5 3,292 Aug-12-2020, 10:34 PM
Last Post: snippsat
  python library not defined in user defined function johnEmScott 2 3,887 May-30-2020, 04:14 AM
Last Post: DT2000
  Error: variable can not be defined julio2000 2 3,213 Feb-09-2020, 08:51 PM
Last Post: julio2000
  Variable defined but python wont recognize it. FWendeburg 3 3,337 Feb-19-2019, 10:43 PM
Last Post: woooee
  How do you make functions that take a variable that is not defined? magic 6 4,441 Sep-24-2018, 01:30 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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