How to update LabelFrame title (Tkinter)

后端 未结 1 594
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 04:43

I am a novice and working with Tkinter for the first time. My project is an \"I Spy\" book which moves picture to picture utilizing buttons. I like the look of the LabelFrame wi

相关标签:
1条回答
  • 2021-01-25 05:24

    If you have some questions about the exampel I'll try to answer you.

        import tkinter as tk
    #you dont need this but if you want to cycle, wich is would be nice there you go
    from itertools import cycle
    
    #create a list with strings you like to display
    li = ['A rainbow, not in the sky!','Dangly, weird seed pods.','A stoney grin.',
          'A lane just for bikes.','A different way to count.']
    #here we create a cycle of that list
    my_cycled_li = cycle(li)
    
    #the change function
    def change():
      #set var to next element in list
      var.set(next(my_cycled_li))
      #update the LabelFrame
      lf.configure(text=var.get())
    
    root = tk.Tk()
    #variable to change
    var = tk.StringVar()
    #there can be a default setting
    var.set('default')
    lf = tk.LabelFrame(root,text=var.get(),width=200,height=100,bg='red')
    #you dont need this, this means the Frame size isnt the size of the widget it contains.
    lf.pack_propagate(0)
    lf.pack()
    b = tk.Button(lf,text='change', command=change)
    b.pack()
    
    
    root.mainloop()
    

    hoped it helps.

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