Python – GUI (Grid Layout)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

 

gui2

 

 

Our output should be the same as below:

 

gui1

 

 

Explanation:

 

These lines:

Label(master, text=”Name:”).grid(row=0)
Label(master, text=”Age:”).grid(row=1)

– one way of declaring one or more labels and giving them their position in the grid

While these lines:

E1 = Entry(master)
E2 = Entry(master)

E1.grid(row=0, column=1)
E2.grid(row=1, column=1)

-another way of declaring one or more textboxes then giving their position in separate lines.

 

Thank you for reading this post.

Don’t forget to leave a comment or suggestion. πŸ™‚

Advertisements

Python – GUI (Label and Textbox)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

gui1

 

Our output should be the same as below:

gui2

 

 

Explanation:

 

The lines:

top = Tk()

top.mainloop()

– are used to initialize the form

 

The lines:

L1 = Label(top, text=”First Name”)

L1.pack( side = LEFT)

-used to initialize and position the Label to the left with a caption of First Name

 

The lines:

E1 = Entry(top, bd =5)

E1.pack(side = RIGHT)

-used to initialize and position the text box to the right.

 

Thank you very much for reading this post.

Don’t forget to leave a comment or suggestion. πŸ™‚

Python – GUI (Button)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

gui1

 

Our output should be the same as below:

gui2

gui3

 

There are several points needed to be explained here.
The import keyword on the first two lines are used to use the libraries native to Python.
Tkinter and tkMessageBox are used for basic GUI Programming.

The lines:

top = Tkinter.Tk()
B.pack()
top.mainloop()

are used to initialize the main form of the program

On this part:

def helloCallBack():
tkMessageBox.showinfo(“Hello Python”, “Hello World”)

  • the def keyword is the same as the function block in other languages
  • the showinfo has two parameters which are:
    “Hello Python” is the used as the title of the Message Box
    “Hello World” is the message inside the Message Box

The line:

B = Tkinter.Button(top, text =”Hello”, command = helloCallBack)

is the initialization of the Button which contains three parameters
top is the position of the button inside the box
text is the String that is used to name the button
command points to function where the button goes when it is clicked

 

Thank you for reading my post.
Don’t forget to leave a comment.

Python – If Statement

Most of the time, every programmer feels the need to compare on or two values of variables in your program. Same as most of the programming languages, Python also has its syntax for the If Statement. In this article, I created a program that uses an if statement after the variables x, and y are declared. I assigned values 10 and 5 to variables x and y respectively.

The program is below:

if1

Your output should be the same as here:

if2

Thank you for reading this post.

Don’t forget to leave a comment.

Python – Loops(While Loop)

This article is a continuation of this last post:
https://arjunaraneta.wordpress.com/2014/08/26/python-loopsfor-loop/

The difference is I used a while in this program. The syntax of the for and while loops and different in terms of the codes used but the concept of a block with a starting value, ending value, and a process of increase and decrease are the same.

 

Here is my code.

loop3

 

Your output should be the same as below:
loop2

 

Thank you for reading this post.

Python – Loops(For Loop)

Most of the time, students get confused of the usage of looping. I always say, “Imagine a block of code that prints 10 consecutive numbers. One way of doing it is by printing them one-by-one. That would be easy if printing 10 numbers is the case but if your program needs to print 1000 numbers then that would be a very long program just for printing. The answer to that problem is looping. If you use a loop, you just define a starting point, a condition of where you are going to stop, and the process if it is increasing or decreasing. A block of 1000 codes would just take three to four lines of codes.”

 

In this program we are going to use a loop called a for loop. I used a variable x to hold the value that will be printed then I declared the starting value and ending value which are inside the range.

Below is my program.

loop1

 

Here is my output:

loop2

 

Thank you for reading this post. πŸ™‚

Python – Arithmetic Operations Basics

One of the most used syntax in a language are the arithmetic operations. Operations like addition, subtraction, multiplication, division, and modulus are the basics. I created a program that shows the syntax for them. I first declared two variables namely x and y. Β Then I performed the arithmetic operations using each variables in the following lines.

The code is below:
math1

 

Click run then select run module.

The output should be same as below:

 

math2

 

Thank you for reading this post.