python_by_example/tkgui/tk02.py
2023-11-17 13:26:09 -03:00

32 lines
1.0 KiB
Python

import tkinter as tk
from random import randint
def tk_02():
"""Write a program that can be used instead of rolling a six-sided die in a
board game. When the user clicks a button it should display a random
whole number between 1 to 6 (inclusive)."""
def click():
num = randint(1,6)
txt_out_box["fg"] = "black"
txt_out_box["bg"] = "magenta"
txt_out_box["text"] = f"{num}"
window = tk.Tk()
window.title("Dado TK")
window.geometry("380x450")
lbl_info = tk.Label(text="Dado", font="Verdana 50")
lbl_info.place(x=40, y=25, width=300, height=75)
txt_out_box = tk.Message(text="", font="Verdana 120")
txt_out_box["fg"] = "red"
txt_out_box["bg"] = "cyan"
txt_out_box["justify"] = "center"
txt_out_box["width"] = 250
txt_out_box.place(x=40, y=120, width=300, height=300)
btn_launch = tk.Button(text="LANZAR DADO", command=click)
btn_launch.place(x=40, y=100, width=300, height=35)
btn_launch.focus()
window.mainloop()