GUI in Python (Graphical User Interface)
Hey Guys,
Today i will be teaching on how to make a Graphical User Interface (GUI) on Python and will be sharing the code.
Let me first introduce the code first and then go with explaining it. But before going into the Topic, be sure to read one of my Blog Posts: Awareness on Snakes.
GUI Code:
The Code for the GUI is the Following:
import tkinter as tk
from tkinter import *
window = tk.Tk()
Q1 = tk.Label(text = "What is Today's Day? ")
Q1.pack()
def Monday():
L1 = tk.Label(text = "Wrong! You did not get it Right!")
L1.pack()
def Wednesday():
L2 = tk.Label(text = "Wrong! You did not get it Right.")
L2.pack()
def Saturday():
L3 = tk.Label(text = "Correct! You get it Right.")
L3.pack()
def Thursday():
L4 = tk.Label(text = "Wrong! You did not get it Right!")
L4.pack()
Button1 = tk.Button(text = "Monday", command=Monday, width = "12")
Button1.pack()
Button2 = tk.Button(text = "Wednesday", command=Wednesday)
Button2.pack()
Button3 = tk.Button(text = "Saturday", command=Saturday)
Button3.pack()
Button4 = tk.Button(text = "Sunday", command=Thursday)
Button4.pack()
window.mainloop()
The Above Code has Saturday as the Correct Answer because of the day this post was written on.
So this Code is basically a Program that executes a Window that asks the current day. It also displays Correct or Wrong. Don't just think this is Easy, We have done many Projects like Game and Calculators, Be Sure to visit them which are actually Text based and need less amount of Code. But this one is a GUI one which displays a Window and requires a huge amount of Code.
Explaining the Code:
1. We import the Tkinter as Tk (this can be your wish) to make it easier to call.
2.Then we introduce the window and then the labels and button. I will be teaching on the basics of Tkinter later but if you know, i have given the button a command and then the label displays if it is correct.
3.We put everything in a Function to make it understandable and easy to call.
4.We have called everything and it's Finished.
Hope you Loved today's Post and be sure to share it with 20 of your friends and family
Please View, Read, Share, Follow, Subscribe, Comment, Review, Support
By the Blog Author.
0 Comments