Testing the tkinter libraries

Testing the tkinter libraries

I'm on day 27 of my online course and just learned about arguments and kwargs. These concepts are beneficial for handling multiple or unlimited positional parameters in functions, which is fun. I didn't realize these concepts were already available in Python.

After that, the teacher introduced us to GUI programming. We started a simple project where you can click a button to convert a number from miles to kilometers. I used to work with Visual Basic, where you drag and drop objects, but in Python, everything is hardcoded. It’s a bit tedious, but also very enjoyable.

Here’s the code that demonstrates how to use the Tkinter library. I utilized different objects like labels, buttons, and entries, and used the grid method to place all my widgets:

You can copy the code below for educational purposes.


from tkinter import *
window = Tk()
window.title("Mile to KM Converter")
window.minsize(width=200, height=100)

entry = Entry(width=10)
entry.grid(column=1,row=0)

label1 = Label(text="is equal to")
label1.grid(column=0,row=1)

label2 = Label(text="Miles")
label2.grid(column=2,row=0)

label3 = Label(text="Km")
label3.grid(column=2,row=1)
converted_mile = Label(text="0")
converted_mile.grid(column=1,row=1)

def calculate_km():
    x = int(entry.get())
    x *= 1.609344
    x = int(round(x,0))
    converted_mile.config(text=x)
    print(x)
button = Button(text="Calculate", command=calculate_km)
button.grid(column=1,row=2)



window.mainloop()

        

要查看或添加评论,请登录

King Mhar Bayato的更多文章

  • Creating Automated Birthday Greetings

    Creating Automated Birthday Greetings

    In today’s digital age, automating routine tasks can save time and add a personal touch to interactions. One such task…

    1 条评论
  • Creating a Local Password Manager Using Python and Tkinter

    Creating a Local Password Manager Using Python and Tkinter

    Managing passwords for various accounts can be daunting in today's digital age. This challenge led me to follow a…

    2 条评论
  • Part 1 of Building a Snake Game ( DAY 22 )

    Part 1 of Building a Snake Game ( DAY 22 )

    After an intense 20-day learning streak in the Python BootCamp, I took a much-needed three-week break. I was exhausted,…

  • Day 15, Coffee Project

    Day 15, Coffee Project

    Day 15 of my course, and my final project for the beginner class is to simulate a coffee vending machine. The…

  • Building a Follower Comparison Game in Python

    Building a Follower Comparison Game in Python

    In this tutorial, we'll walk through creating an engaging follower comparison game using Python. The game uses random…

  • Guess the Number

    Guess the Number

    The instructor tested our knowledge by assigning us a task to develop specific programs. Surprisingly, I managed to…

  • The Basic Blackjack or 21 in Python

    The Basic Blackjack or 21 in Python

    In developing a mini blackjack game, I first used the teacher's flowchart to outline the game's logic, ensuring clarity…

  • Day 10 of python boot camp

    Day 10 of python boot camp

    In this Python boot camp session, the main project revolves around creating a program known as the "secret auction…

  • Day 8 of Python Bootcamp

    Day 8 of Python Bootcamp

    We have been tasked with creating a Caesar cipher program for encoding and decoding. This project presents some…

  • Building 'Hangman': A Developer's Experience at an Online Bootcamp

    Building 'Hangman': A Developer's Experience at an Online Bootcamp

    During a seven-day online boot camp, a novice programmer embarked on a journey to create a mini-game called "Hangman."…

社区洞察

其他会员也浏览了