How to get the Tkinter Label text?

前端 未结 2 1362
灰色年华
灰色年华 2020-12-08 10:37

Im making a list of addresses that the user will select from, and the address text will be returned. I need to use Tkinter.Label because the Tkinter.List

相关标签:
2条回答
  • 2020-12-08 11:21
    label = Label(text = 'Hello, World!')
    print(label['text']) # output is: Hello, World!
    
    0 讨论(0)
  • 2020-12-08 11:27

    To get the value out of a label you can use the cget method, which can be used to get the value of any of the configuration options.

    For example:

    l = tk.Label(text="hello, world")
    ...
    print("the label is", l.cget("text"))
    

    You can also treat the object as a dictionary, using the options as keys. Using the same example you can use l["text"].

    0 讨论(0)
提交回复
热议问题