Python 3, Tkinter, How to update button text

后端 未结 7 1725
孤城傲影
孤城傲影 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:59

    I think that code will be useful for you.

    import tkinter 
    from tkinter import *
    #These Necessary Libraries
    
    App = Tk()
    App.geometry("256x192")
    
    def Change():
        Btn1.configure(text=Text.get()) # Changes Text As Entry Message.
        Ent1.delete(first=0, last=999) # Not necessary. For clearing Entry.
    
    Btn1 = Button(App, text="Change Text", width=16, command=Change)
    Btn1.pack()
    
    Text = tkinter.StringVar() # For Pickup Text
    
    Ent1 = Entry(App, width=32, bd=3, textvariable=Text) #<-
    Ent1.pack()
    
    App.mainloop()
    

提交回复
热议问题