Sinisterly
Python guide [Basics & Gui] - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Python guide [Basics & Gui] (/Thread-Python-guide-Basics-Gui)

Pages: 1 2


Python guide [Basics & Gui] - Guxi - 01-14-2013

Tutorial for python beginners.
[Image: python-logo-master-flat.png]


my experience in python programming

If you are new to programming python should be great choice for you, but it also comes with few bad things. Python is good because it's kinda lightweight, simple, understandable syntaxes, huge library of modules and extensions...
Python is possible to understand even if you aren't python programmer, because it's kinda familiar with pseudo.

What's bad in python?
Well windows, if you want to make a program that is predicted to be ran on windows you will have to pack a python library with your application because python is not installed on windows by default. So there you might come a cross some problems. Most popular 'compilers' are py2exe,pyinstaller and maybe cython( which works with c++, but 'm not familiar with it).

I recommend you to install python 2.7.3v because it's most popular, used cyberwide in py programming.


In this tutorial i will introduce you with basics of python and python gui development.



Making your first 'Hello World' program.


Code:
print "Hello World"
Code above will give you output with text "Hello World".

Now there is 3 types of value that you will need to know:
string It's always stored in " "
If you wrote
Code:
print Hello World
You would get error, because Hello World is not recognized as string or int, so you have to put hello world in " ", to make it a string.

integer
example of integer is
Code:
4
, int is used for math operations. If you put 4 in " ", then it will become a string, and you won't be able to do math operations with it, because it's considered as string.

Booleans
They can be only True or False. In programming you will have to get a true or false for many things. For example, if you need to check does a specific file exists, if it does exist, your code will return you statement: True.


Variables

You use them to store some kind of value in them. They are like backpacks which are carrying some kind of value (string,int,boolean). To declare a variable and assign a value to it you need to do following:
Code:
my_variable = "Hello World"
Now variable named my_variable get's new value, which is in this case a string with text Hello World.
Variables are one of most important things in python, so you need to use it everywhere.
Now if you want to display/print value of variable called my variable, you will have to do following:
Code:
print my_variable
program will display you text "Hello World".

Get input from user
For getting input from user you will need to use
Code:
raw_input()
raw_input command always needs to have brackets after itself, because that command can take one argument. It's not necessary to put anything inside of it, but anything you put will be displayed to user, like print command does.

Now variables will help you. To save user's input from raw_input() command, you will need to store them in variable.
Code:
my_variable = raw_input()

Now my_variable will get new value, depending on what user writes as input to program.
To display users input you will need to print variable that you declared with raw_input()
in this case:
Code:
print my_variable


variables example
I'm gonna show you how to ask user his name,age,location and then we will display it to him in same sentence.
Your mission is to ask user 3 questions what's his name, age and location.
Code:
name = raw_input("Your name: ")
age = raw_input("Your age: ")
location = raw_input("Where are you from: ")

print "Your name is " name " and you are " str(age) " old"
print " You are also from " location

Now you might be asking what str() does?
Well it will convert anything inside of brackets to string. In this case we were expecting user to enter the int type of value. There is also int() which can convert "5" to 5 so you could do math with it for example.

playing with strings
You can replace specific part of strings. For example "How to learn hacking?"
If you want to remove "how to" part you can do following:
Code:
word = "How to learn hacking?"
word = word.replace("How to","")
print word

Code above will print you "learn hacking?"
You replaced string "How to" with "" ( nothing, no chars = nothing )


IF statement

In programming you need to make more space for possibilities and alternatives. If statement will allow you to make unlimited number of alternatives.

This is how if statement works in theory:
Code:
if expression:
   statement(s)
else:
   statement(s)
[Image: if_else_statement.jpg]

For constructing the expression, you will commonly use
Code:
>
<      #greater than
=      # equal to
+=   #not equal

<=  #greater or equal to
>=


expressions

We are going to ask user to give us number between 1 and 10, if he doesn't give us number in that range, we print him msg that it's not in range 1-10.

Code:
print "enter any number in range 1-10"
answer = raw_input()
if answer > 10 and > 0:   # checks if  it's greater than 10 and lower than  0
     print "It's in range"     # <- executed if expression is true
else:
    print "it's not in range 1-10" # Executed if expression isn't true

We used and because we need to make sure that it's not higher than 10 and lower than 0. So we need to check for 2 things.
Imagine if you had to make 2 if statements, one checks is it greater than 10 and other one checks if it's lower than 0. That's why and helps so much.

Ask user for password
Now user will have to type correct password in order to proceed to next part of program.
Code:
password = "aeiou"   # we are declaring variable in which we are storing the password
print "enter the password"  
pass = raw_Input()

if pass = password:       # checks if user input is same as our password ("aeiou")
    print "Correct password"
else:
    print "wrong password"
So if expression is true ( if password is correct) you will get output "correct password"
else, you will get "wrong password"
note: don't use this kind of password protection if it's important for you



Functions


Functions are very important, because it makes more functional :epic:.
Theres no program without a single function. ( there is but non-practical ones)
to define a function you will use def, also everything inside a function must be in indentation.

Code:
def my_function():
    #statement(s)

As you see every function has brackets, which means that they are capable of taking some arguments.( will get to that later)

To call/start a function you need to do following
Code:
my_function()
When you it comes to executing my_function() everything inside of that function will be executed.

for example:
Code:
def welcome(name):
     print "Welcome to function " name


answer = raw_input("what's your name? ")
welcome(answer)

You would get output with "welcome to function name_you_entered
You might be asking why couldn't we just do
Code:
print "welcome to function " answer
instead of
Code:
print "welcome to function " name

Well it's because answer is not global variable, so we have to 'import' it to function by giving it arguments.

So inside of functions you can put anything but make sure that it's in indentation.

Modules



those are important because they expand possibilities of your program.
you import one by doing following:
Code:
import [i]module_name[/i]

Module that provides you GUI library is called tkinter, so you would write:
Code:
import Tkinter




Python graphical user interface

gui library that we are using will be Tkinter. It's simple and easy!

Make sure you import the module for GUI
Code:
import Tkinter

First thing that we could possibly do is to define a master/parent window. We will use name "root" for master window.

Code:
import Tkinter   # GUI module imported

root = Tk()   # Defining master window

root.mainloop()
Now we have "root" as parent window. You probably noticed root.mainloop()
It makes sure that your window doesn't destroy, it needs to loop.
Same thing if you do
Code:
print "hello world"
It will close in 1 second... Solution is to add raw_input() so it won't close before you enter something.
[Image: tkwindow.jpg]
Now we made a simplest gui program, that will make a empty window. But now let's go further!

Let's add title and geometry to our program!
Code:
import Tkinter                     # GUI module imported

root = Tk()                          # Defining master window
root.title("HC tutorial")        # title of program
root.geometry(300x300)    # default size by pixels
root.maxsize(350,350)       # maximal resize size
root.minszie(250,250         # minimal resize size

root.mainloop()
Now you chosen maximal and minimal and default size of program, also the title of program.


Adding widgets

All the things that will replace your CLI commands to new one using Tk module

label

This will actually replace the print in CLI.
Label is way to output a value to user.

Now you have to define the label:
Code:
mytext = Label(root,text="HackCommunity",bg="black",fg="red")
mytext.pack()
first item that goes in bracket is parent window, in this case it's "root"
That's the only thing that must be first.
___label config______
text will display "HackCommunity" text
bg Color of label's background
fg Color of text
_______________

mytext.pack() Will actually pack your widgets like in tetris, to the first spot available.
You could also use .grid() .place() <- this one is used for navigating your widget by pixels.


Entry
Used instead of raw_input() or input().

Code:
box = Entry(root, width="30")
box.pack()

width of entry box is set to 30 pixels.


Button
Button is very important, because that's the most common way of starting a function or similar..

Code:
my_button = Button(root,text="Click here",fg="green",borderwidth="0")
my_button.pack

Text inside of button is "Click here" font color is green, and there is border on the button, because we set it 0.


Making program GUI functional


To activate a function by button you will need to add command= property to button.
Code:
def myfunc():
    hello = Label(root, text="Hello")
    hello.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()

Now when you click on the button, you will activate myfunc function, and it will create a new label with text "Hello".


Now let's add Entry to the same code.
We will ask user to write his name in entry box:
Code:
def myfunc():
     name = name.wget()
    hello = Label(root, text="Hello" name)
    hello.pack


name = Entry(root)
name.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()
Now the code above will take input from user, from entry widget and display "hello" user input through label.






[username] I hope you enjoy this tutorial!
Tutorial is written by me 100%, i will add some more stuff here but this is enough for start.

I invested my time for new programmers, Rep appreciated
Thanks!


Will be updated



Python guide [Basics & Gui] - Guxi - 01-14-2013

Tutorial for python beginners.
[Image: python-logo-master-flat.png]


my experience in python programming

If you are new to programming python should be great choice for you, but it also comes with few bad things. Python is good because it's kinda lightweight, simple, understandable syntaxes, huge library of modules and extensions...
Python is possible to understand even if you aren't python programmer, because it's kinda familiar with pseudo.

What's bad in python?
Well windows, if you want to make a program that is predicted to be ran on windows you will have to pack a python library with your application because python is not installed on windows by default. So there you might come a cross some problems. Most popular 'compilers' are py2exe,pyinstaller and maybe cython( which works with c++, but 'm not familiar with it).

I recommend you to install python 2.7.3v because it's most popular, used cyberwide in py programming.


In this tutorial i will introduce you with basics of python and python gui development.



Making your first 'Hello World' program.


Code:
print "Hello World"
Code above will give you output with text "Hello World".

Now there is 3 types of value that you will need to know:
string It's always stored in " "
If you wrote
Code:
print Hello World
You would get error, because Hello World is not recognized as string or int, so you have to put hello world in " ", to make it a string.

integer
example of integer is
Code:
4
, int is used for math operations. If you put 4 in " ", then it will become a string, and you won't be able to do math operations with it, because it's considered as string.

Booleans
They can be only True or False. In programming you will have to get a true or false for many things. For example, if you need to check does a specific file exists, if it does exist, your code will return you statement: True.


Variables

You use them to store some kind of value in them. They are like backpacks which are carrying some kind of value (string,int,boolean). To declare a variable and assign a value to it you need to do following:
Code:
my_variable = "Hello World"
Now variable named my_variable get's new value, which is in this case a string with text Hello World.
Variables are one of most important things in python, so you need to use it everywhere.
Now if you want to display/print value of variable called my variable, you will have to do following:
Code:
print my_variable
program will display you text "Hello World".

Get input from user
For getting input from user you will need to use
Code:
raw_input()
raw_input command always needs to have brackets after itself, because that command can take one argument. It's not necessary to put anything inside of it, but anything you put will be displayed to user, like print command does.

Now variables will help you. To save user's input from raw_input() command, you will need to store them in variable.
Code:
my_variable = raw_input()

Now my_variable will get new value, depending on what user writes as input to program.
To display users input you will need to print variable that you declared with raw_input()
in this case:
Code:
print my_variable


variables example
I'm gonna show you how to ask user his name,age,location and then we will display it to him in same sentence.
Your mission is to ask user 3 questions what's his name, age and location.
Code:
name = raw_input("Your name: ")
age = raw_input("Your age: ")
location = raw_input("Where are you from: ")

print "Your name is " name " and you are " str(age) " old"
print " You are also from " location

Now you might be asking what str() does?
Well it will convert anything inside of brackets to string. In this case we were expecting user to enter the int type of value. There is also int() which can convert "5" to 5 so you could do math with it for example.

playing with strings
You can replace specific part of strings. For example "How to learn hacking?"
If you want to remove "how to" part you can do following:
Code:
word = "How to learn hacking?"
word = word.replace("How to","")
print word

Code above will print you "learn hacking?"
You replaced string "How to" with "" ( nothing, no chars = nothing )


IF statement

In programming you need to make more space for possibilities and alternatives. If statement will allow you to make unlimited number of alternatives.

This is how if statement works in theory:
Code:
if expression:
   statement(s)
else:
   statement(s)
[Image: if_else_statement.jpg]

For constructing the expression, you will commonly use
Code:
>
<      #greater than
=      # equal to
+=   #not equal

<=  #greater or equal to
>=


expressions

We are going to ask user to give us number between 1 and 10, if he doesn't give us number in that range, we print him msg that it's not in range 1-10.

Code:
print "enter any number in range 1-10"
answer = raw_input()
if answer > 10 and > 0:   # checks if  it's greater than 10 and lower than  0
     print "It's in range"     # <- executed if expression is true
else:
    print "it's not in range 1-10" # Executed if expression isn't true

We used and because we need to make sure that it's not higher than 10 and lower than 0. So we need to check for 2 things.
Imagine if you had to make 2 if statements, one checks is it greater than 10 and other one checks if it's lower than 0. That's why and helps so much.

Ask user for password
Now user will have to type correct password in order to proceed to next part of program.
Code:
password = "aeiou"   # we are declaring variable in which we are storing the password
print "enter the password"  
pass = raw_Input()

if pass = password:       # checks if user input is same as our password ("aeiou")
    print "Correct password"
else:
    print "wrong password"
So if expression is true ( if password is correct) you will get output "correct password"
else, you will get "wrong password"
note: don't use this kind of password protection if it's important for you



Functions


Functions are very important, because it makes more functional :epic:.
Theres no program without a single function. ( there is but non-practical ones)
to define a function you will use def, also everything inside a function must be in indentation.

Code:
def my_function():
    #statement(s)

As you see every function has brackets, which means that they are capable of taking some arguments.( will get to that later)

To call/start a function you need to do following
Code:
my_function()
When you it comes to executing my_function() everything inside of that function will be executed.

for example:
Code:
def welcome(name):
     print "Welcome to function " name


answer = raw_input("what's your name? ")
welcome(answer)

You would get output with "welcome to function name_you_entered
You might be asking why couldn't we just do
Code:
print "welcome to function " answer
instead of
Code:
print "welcome to function " name

Well it's because answer is not global variable, so we have to 'import' it to function by giving it arguments.

So inside of functions you can put anything but make sure that it's in indentation.

Modules



those are important because they expand possibilities of your program.
you import one by doing following:
Code:
import [i]module_name[/i]

Module that provides you GUI library is called tkinter, so you would write:
Code:
import Tkinter




Python graphical user interface

gui library that we are using will be Tkinter. It's simple and easy!

Make sure you import the module for GUI
Code:
import Tkinter

First thing that we could possibly do is to define a master/parent window. We will use name "root" for master window.

Code:
import Tkinter   # GUI module imported

root = Tk()   # Defining master window

root.mainloop()
Now we have "root" as parent window. You probably noticed root.mainloop()
It makes sure that your window doesn't destroy, it needs to loop.
Same thing if you do
Code:
print "hello world"
It will close in 1 second... Solution is to add raw_input() so it won't close before you enter something.
[Image: tkwindow.jpg]
Now we made a simplest gui program, that will make a empty window. But now let's go further!

Let's add title and geometry to our program!
Code:
import Tkinter                     # GUI module imported

root = Tk()                          # Defining master window
root.title("HC tutorial")        # title of program
root.geometry(300x300)    # default size by pixels
root.maxsize(350,350)       # maximal resize size
root.minszie(250,250         # minimal resize size

root.mainloop()
Now you chosen maximal and minimal and default size of program, also the title of program.


Adding widgets

All the things that will replace your CLI commands to new one using Tk module

label

This will actually replace the print in CLI.
Label is way to output a value to user.

Now you have to define the label:
Code:
mytext = Label(root,text="HackCommunity",bg="black",fg="red")
mytext.pack()
first item that goes in bracket is parent window, in this case it's "root"
That's the only thing that must be first.
___label config______
text will display "HackCommunity" text
bg Color of label's background
fg Color of text
_______________

mytext.pack() Will actually pack your widgets like in tetris, to the first spot available.
You could also use .grid() .place() <- this one is used for navigating your widget by pixels.


Entry
Used instead of raw_input() or input().

Code:
box = Entry(root, width="30")
box.pack()

width of entry box is set to 30 pixels.


Button
Button is very important, because that's the most common way of starting a function or similar..

Code:
my_button = Button(root,text="Click here",fg="green",borderwidth="0")
my_button.pack

Text inside of button is "Click here" font color is green, and there is border on the button, because we set it 0.


Making program GUI functional


To activate a function by button you will need to add command= property to button.
Code:
def myfunc():
    hello = Label(root, text="Hello")
    hello.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()

Now when you click on the button, you will activate myfunc function, and it will create a new label with text "Hello".


Now let's add Entry to the same code.
We will ask user to write his name in entry box:
Code:
def myfunc():
     name = name.wget()
    hello = Label(root, text="Hello" name)
    hello.pack


name = Entry(root)
name.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()
Now the code above will take input from user, from entry widget and display "hello" user input through label.






[username] I hope you enjoy this tutorial!
Tutorial is written by me 100%, i will add some more stuff here but this is enough for start.

I invested my time for new programmers, Rep appreciated
Thanks!


Will be updated



Python guide [Basics & Gui] - Guxi - 01-14-2013

Tutorial for python beginners.
[Image: python-logo-master-flat.png]


my experience in python programming

If you are new to programming python should be great choice for you, but it also comes with few bad things. Python is good because it's kinda lightweight, simple, understandable syntaxes, huge library of modules and extensions...
Python is possible to understand even if you aren't python programmer, because it's kinda familiar with pseudo.

What's bad in python?
Well windows, if you want to make a program that is predicted to be ran on windows you will have to pack a python library with your application because python is not installed on windows by default. So there you might come a cross some problems. Most popular 'compilers' are py2exe,pyinstaller and maybe cython( which works with c++, but 'm not familiar with it).

I recommend you to install python 2.7.3v because it's most popular, used cyberwide in py programming.


In this tutorial i will introduce you with basics of python and python gui development.



Making your first 'Hello World' program.


Code:
print "Hello World"
Code above will give you output with text "Hello World".

Now there is 3 types of value that you will need to know:
string It's always stored in " "
If you wrote
Code:
print Hello World
You would get error, because Hello World is not recognized as string or int, so you have to put hello world in " ", to make it a string.

integer
example of integer is
Code:
4
, int is used for math operations. If you put 4 in " ", then it will become a string, and you won't be able to do math operations with it, because it's considered as string.

Booleans
They can be only True or False. In programming you will have to get a true or false for many things. For example, if you need to check does a specific file exists, if it does exist, your code will return you statement: True.


Variables

You use them to store some kind of value in them. They are like backpacks which are carrying some kind of value (string,int,boolean). To declare a variable and assign a value to it you need to do following:
Code:
my_variable = "Hello World"
Now variable named my_variable get's new value, which is in this case a string with text Hello World.
Variables are one of most important things in python, so you need to use it everywhere.
Now if you want to display/print value of variable called my variable, you will have to do following:
Code:
print my_variable
program will display you text "Hello World".

Get input from user
For getting input from user you will need to use
Code:
raw_input()
raw_input command always needs to have brackets after itself, because that command can take one argument. It's not necessary to put anything inside of it, but anything you put will be displayed to user, like print command does.

Now variables will help you. To save user's input from raw_input() command, you will need to store them in variable.
Code:
my_variable = raw_input()

Now my_variable will get new value, depending on what user writes as input to program.
To display users input you will need to print variable that you declared with raw_input()
in this case:
Code:
print my_variable


variables example
I'm gonna show you how to ask user his name,age,location and then we will display it to him in same sentence.
Your mission is to ask user 3 questions what's his name, age and location.
Code:
name = raw_input("Your name: ")
age = raw_input("Your age: ")
location = raw_input("Where are you from: ")

print "Your name is " name " and you are " str(age) " old"
print " You are also from " location

Now you might be asking what str() does?
Well it will convert anything inside of brackets to string. In this case we were expecting user to enter the int type of value. There is also int() which can convert "5" to 5 so you could do math with it for example.

playing with strings
You can replace specific part of strings. For example "How to learn hacking?"
If you want to remove "how to" part you can do following:
Code:
word = "How to learn hacking?"
word = word.replace("How to","")
print word

Code above will print you "learn hacking?"
You replaced string "How to" with "" ( nothing, no chars = nothing )


IF statement

In programming you need to make more space for possibilities and alternatives. If statement will allow you to make unlimited number of alternatives.

This is how if statement works in theory:
Code:
if expression:
   statement(s)
else:
   statement(s)
[Image: if_else_statement.jpg]

For constructing the expression, you will commonly use
Code:
>
<      #greater than
=      # equal to
+=   #not equal

<=  #greater or equal to
>=


expressions

We are going to ask user to give us number between 1 and 10, if he doesn't give us number in that range, we print him msg that it's not in range 1-10.

Code:
print "enter any number in range 1-10"
answer = raw_input()
if answer > 10 and > 0:   # checks if  it's greater than 10 and lower than  0
     print "It's in range"     # <- executed if expression is true
else:
    print "it's not in range 1-10" # Executed if expression isn't true

We used and because we need to make sure that it's not higher than 10 and lower than 0. So we need to check for 2 things.
Imagine if you had to make 2 if statements, one checks is it greater than 10 and other one checks if it's lower than 0. That's why and helps so much.

Ask user for password
Now user will have to type correct password in order to proceed to next part of program.
Code:
password = "aeiou"   # we are declaring variable in which we are storing the password
print "enter the password"  
pass = raw_Input()

if pass = password:       # checks if user input is same as our password ("aeiou")
    print "Correct password"
else:
    print "wrong password"
So if expression is true ( if password is correct) you will get output "correct password"
else, you will get "wrong password"
note: don't use this kind of password protection if it's important for you



Functions


Functions are very important, because it makes more functional :epic:.
Theres no program without a single function. ( there is but non-practical ones)
to define a function you will use def, also everything inside a function must be in indentation.

Code:
def my_function():
    #statement(s)

As you see every function has brackets, which means that they are capable of taking some arguments.( will get to that later)

To call/start a function you need to do following
Code:
my_function()
When you it comes to executing my_function() everything inside of that function will be executed.

for example:
Code:
def welcome(name):
     print "Welcome to function " name


answer = raw_input("what's your name? ")
welcome(answer)

You would get output with "welcome to function name_you_entered
You might be asking why couldn't we just do
Code:
print "welcome to function " answer
instead of
Code:
print "welcome to function " name

Well it's because answer is not global variable, so we have to 'import' it to function by giving it arguments.

So inside of functions you can put anything but make sure that it's in indentation.

Modules



those are important because they expand possibilities of your program.
you import one by doing following:
Code:
import [i]module_name[/i]

Module that provides you GUI library is called tkinter, so you would write:
Code:
import Tkinter




Python graphical user interface

gui library that we are using will be Tkinter. It's simple and easy!

Make sure you import the module for GUI
Code:
import Tkinter

First thing that we could possibly do is to define a master/parent window. We will use name "root" for master window.

Code:
import Tkinter   # GUI module imported

root = Tk()   # Defining master window

root.mainloop()
Now we have "root" as parent window. You probably noticed root.mainloop()
It makes sure that your window doesn't destroy, it needs to loop.
Same thing if you do
Code:
print "hello world"
It will close in 1 second... Solution is to add raw_input() so it won't close before you enter something.
[Image: tkwindow.jpg]
Now we made a simplest gui program, that will make a empty window. But now let's go further!

Let's add title and geometry to our program!
Code:
import Tkinter                     # GUI module imported

root = Tk()                          # Defining master window
root.title("HC tutorial")        # title of program
root.geometry(300x300)    # default size by pixels
root.maxsize(350,350)       # maximal resize size
root.minszie(250,250         # minimal resize size

root.mainloop()
Now you chosen maximal and minimal and default size of program, also the title of program.


Adding widgets

All the things that will replace your CLI commands to new one using Tk module

label

This will actually replace the print in CLI.
Label is way to output a value to user.

Now you have to define the label:
Code:
mytext = Label(root,text="HackCommunity",bg="black",fg="red")
mytext.pack()
first item that goes in bracket is parent window, in this case it's "root"
That's the only thing that must be first.
___label config______
text will display "HackCommunity" text
bg Color of label's background
fg Color of text
_______________

mytext.pack() Will actually pack your widgets like in tetris, to the first spot available.
You could also use .grid() .place() <- this one is used for navigating your widget by pixels.


Entry
Used instead of raw_input() or input().

Code:
box = Entry(root, width="30")
box.pack()

width of entry box is set to 30 pixels.


Button
Button is very important, because that's the most common way of starting a function or similar..

Code:
my_button = Button(root,text="Click here",fg="green",borderwidth="0")
my_button.pack

Text inside of button is "Click here" font color is green, and there is border on the button, because we set it 0.


Making program GUI functional


To activate a function by button you will need to add command= property to button.
Code:
def myfunc():
    hello = Label(root, text="Hello")
    hello.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()

Now when you click on the button, you will activate myfunc function, and it will create a new label with text "Hello".


Now let's add Entry to the same code.
We will ask user to write his name in entry box:
Code:
def myfunc():
     name = name.wget()
    hello = Label(root, text="Hello" name)
    hello.pack


name = Entry(root)
name.pack

my_button = Button(root,text="click here to activate a function",command=myfunc)
my_button.pack()
Now the code above will take input from user, from entry widget and display "hello" user input through label.






[username] I hope you enjoy this tutorial!
Tutorial is written by me 100%, i will add some more stuff here but this is enough for start.

I invested my time for new programmers, Rep appreciated
Thanks!


Will be updated



RE: Python guide [Basics & Gui] - bluedog.tar.gz - 01-14-2013

Very nice thread, you explained it pretty well.

A hint, mayby some images would work.
Example of this IF statement.

[Image: if_else_statement.jpg]

Other then that +1


RE: Python guide [Basics & Gui] - bluedog.tar.gz - 01-14-2013

Very nice thread, you explained it pretty well.

A hint, mayby some images would work.
Example of this IF statement.

[Image: if_else_statement.jpg]

Other then that +1


RE: Python guide [Basics & Gui] - bluedog.tar.gz - 01-14-2013

Very nice thread, you explained it pretty well.

A hint, mayby some images would work.
Example of this IF statement.

[Image: if_else_statement.jpg]

Other then that +1


RE: Python guide [Basics & Gui] - LightX - 01-14-2013

Great tutorial buddy! Can't wait to see more from you!


RE: Python guide [Basics & Gui] - LightX - 01-14-2013

Great tutorial buddy! Can't wait to see more from you!


RE: Python guide [Basics & Gui] - LightX - 01-14-2013

Great tutorial buddy! Can't wait to see more from you!


RE: Python guide [Basics & Gui] - Guxi - 01-14-2013

Good idea about images, also, i'm glad to hear that Lightx Smile