Python 3, Tkinter, How to update button text

后端 未结 7 1734
孤城傲影
孤城傲影 2020-12-06 08:41

Im trying to make it so that when the user clicks a button, it becomes \"X\" or \"0\" (Depending on their team). How can I make it so that the text on the button is updated?

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 08:57

    btn is just a dictionary of values, lets see what comes up then:

    #lets do another button example
    Search_button
    
    #hmm, lets do dict(Search_button)
    dict(Search_button)
    {'activebackground': 'SystemButtonFace', 'activeforeground': 
    'SystemButtonText', 'anchor': 'center', 'background': 'SystemButtonFace', 
    'bd': , 'bg': 'SystemButtonFace', 'bitmap': '', 
    'borderwidth': , 'command': '100260920point', 'compound': 
    'none', 'cursor': '', 'default': 'disabled', 'disabledforeground': 
    'SystemDisabledText', 'fg': 'SystemButtonText', 'font': 'TkDefaultFont', 
    'foreground': 'SystemButtonText', 'height': 0, 'highlightbackground': 
    'SystemButtonFace', 'highlightcolor': 'SystemWindowFrame', 
    'highlightthickness': , 'image': '', 'justify': 'center', 
    'overrelief': '', 'padx': , 'pady': , 
    'relief': 'raised', 'repeatdelay': 0, 'repeatinterval': 0, 'state': 
    'normal', 'takefocus': '', 'text': 'Click me for 10 points!', 
    'textvariable': '', 'underline': -1, 'width': 125, 'wraplength': }
    #this will not work if you have closed the tkinter window
    

    As you can see, it is a large dictionary of values, so if you want to change any button, simply do:

    Button_that_needs_to_be_changed["text"] = "new text here"
    

    Thats it really!

    It will automatically change the text on the button, even if you are on IDLE!

提交回复
热议问题