An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
June 20, 2022 09:25 am GMT
Original Link: https://dev.to/mathewchan/first-program-with-gui-roll-a-dice-fm4
First program with GUI: Roll a dice
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 randomimport tkinter as tkdef 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.
Original Link: https://dev.to/mathewchan/first-program-with-gui-roll-a-dice-fm4
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To