Python Forum
Button to clear all output labels?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button to clear all output labels?
#2
One way is to use textvariables in your label's the main methods are set and get.
I would make a list of the dice and set them all to ''. here's an example with the 4d only
from tkinter import *
from random import randint
 
def rollD4():
    number= str(randint(1,4))
    dice_1.set(number)
def on_clear():
    dice_1.set('')
    

root = Tk()
root.title("Table Top Pal (beta)")
root.geometry("500x592")  # This is how to resize your root box. (width x height)
menubar = Menu(root)
root.config(menu=menubar)
 
fileMenu = Menu(menubar,tearoff=0)
menubar.add_cascade(label="File",menu=fileMenu)
fileMenu.add_command(label="Exit",command=root.destroy)
dice_1= StringVar()
button1 = Button(root, text="D4", command=rollD4, width=10, height=3)
button1.grid(row=0, column=0)
clear_btn= Button(root, text='Clear All', command= on_clear)
clear_btn.grid(row=2,column=0)

label_1 = Label(root, textvariable=dice_1, font=(None, 12), height=2, width=2).grid(row=0, column=2)
root.mainloop()
Reply


Messages In This Thread
RE: Button to clear all output labels? - by joe_momma - Dec-09-2020, 11:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button/output help swittler 4 2,533 Jun-24-2020, 04:59 PM
Last Post: menator01
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,042 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  clear button destroy can't work jacklee26 1 4,116 Jul-07-2019, 03:44 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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