Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 20, 2022 09:25 am GMT

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()

A program with one button and one label

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To