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 …


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

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.


This content originally appeared on DEV Community and was authored by HHMathewChan


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » First program with GUI: Roll a dice." HHMathewChan | Sciencx - Monday June 20, 2022, https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/
HARVARD
HHMathewChan | Sciencx Monday June 20, 2022 » First program with GUI: Roll a dice., viewed ,<https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/>
VANCOUVER
HHMathewChan | Sciencx - » First program with GUI: Roll a dice. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/
CHICAGO
" » First program with GUI: Roll a dice." HHMathewChan | Sciencx - Accessed . https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/
IEEE
" » First program with GUI: Roll a dice." HHMathewChan | Sciencx [Online]. Available: https://www.scien.cx/2022/06/20/first-program-with-gui-roll-a-dice/. [Accessed: ]
rf:citation
» First program with GUI: Roll a dice | HHMathewChan | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.