This content originally appeared on DEV Community and was authored by HHMathewChan
This times is to record a memorable day for me to create a program which look closer to what will be usable in real life.
Code
This program is to act like a 6-face dice, when you press the button, a number will be randomly picked from 1 to 6 and display it
import random
import tkinter as tk
def random_a_num():
value = int(random.randrange(1, 7))
lbl_value["text"] = f"{value}"
window = tk.Tk()
window.rowconfigure([0, 1], minsize=50, weight=1)
window.columnconfigure(0, minsize=50, weight=1)
btn_roll = tk.Button(master=window, text="Roll", command=random_a_num)
btn_roll.grid(row=0, column=0, sticky="nsew")
lbl_value = tk.Label(master=window, text="0")
lbl_value.grid(row=1, column=0, sticky="nsew")
window.mainloop()
Reflection
I have learned a lot of useful basic syntax and concept in tkinter module. When the interface comes out and it works, I feel like my excitement on learning coding has increase a lot. More confidence to go on the learning path.
This content originally appeared on DEV Community and was authored by HHMathewChan

HHMathewChan | Sciencx (2022-06-20T09:25:26+00:00) First program with GUI: Roll a dice. Retrieved from https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.