dashmahmood
Shoujo Manga Narrator
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this tutorial we will create a Simple Adding Value In Dictionary using Python. Python has a design philosophy which emphasizes code readability. That's why python is very easy to use especially for beginners who just started programming. It is very easy to learn the syntax emphasizes readability and it can reduces time consuming in developing. So let's now do the coding...
Getting started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Importing Modules
After setting up the installation and the database, run the IDLE and click file and then new file. After that a new window will appear containing a black file this will be the text editor for the python.
Then copy code that I provided below and paste it inside the IDLE text editor.
Setting up the Main Frame
After importing the modules, we will now then create the main frame for the application. To do that just copy the code below and paste it inside the IDLE text editor.
Assigning Variables
This is where the we will assign the variables. This code will assign each of the variables to be use later in the application.
Designing the Layout
After creating the Main Frame we will now add some layout to the application. Just kindly copy the code below and paste it inside the IDLE text editor.
Creating the Main Function
This is where the code that contains the main functions. This code will add a new entry to the dictionary when user input some data. To do that just copy and write these blocks of code.
Initializing the Application
After finishing the function save the application as index.py. This function will run the code and check if the main is initialize properly. To do that copy the code below and paste it inside the IDLE text editor.
There you have it we just created a Simple Adding Value In Dictionary Using Python. I hope that this simple tutorial help you for what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Download
Getting started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.
Importing Modules
After setting up the installation and the database, run the IDLE and click file and then new file. After that a new window will appear containing a black file this will be the text editor for the python.
Then copy code that I provided below and paste it inside the IDLE text editor.
- from
tkinter import
*
Setting up the Main Frame
After importing the modules, we will now then create the main frame for the application. To do that just copy the code below and paste it inside the IDLE text editor.
- #==================================MAIN FRAME=====================================
- root=
Tk(
)
- root.title
(
"Python - Simple Adding Value In Dictionary"
)
- width=
450
- height=
300
- screen_width=
root.winfo_screenwidth
(
)
- screen_height=
root.winfo_screenheight
(
)
- x=
(
screen_width/2
)
-(
width/2
)
- y=
(
screen_height/2
)
-(
height/2
)
- root.geometry
(
"%dx%d+%d+%d"
% (
width,
height,
x,
y)
)
- root.resizable
(
0
,
0
)
- #=================================FRAMES==========================================
- Top =
Frame(
root,
relief=
SOLID,
bd=
1
)
- Top.pack
(
fill=
X)
- Mid =
Frame(
root)
- Mid.pack
(
pady=
10
)
- Left =
Frame(
Mid)
- Left.pack
(
side=
LEFT)
- Right =
Frame(
Mid)
- Right.pack
(
side=
RIGHT)
- Bottom =
Frame(
root)
- Bottom.pack
(
)
- Below =
Frame(
root)
- Below.pack
(
)
Assigning Variables
This is where the we will assign the variables. This code will assign each of the variables to be use later in the application.
- #=================================VARIABLES=======================================
- NAME =
StringVar(
)
Designing the Layout
After creating the Main Frame we will now add some layout to the application. Just kindly copy the code below and paste it inside the IDLE text editor.
- #=================================BUTTON WIDGETS==================================
- btn_add =
Button(
Bottom,
text=
"ADD"
,
command=
Add)
- btn_add.pack
(
)
- #=================================LABEL WIDGETS===================================
- lbl_title =
Label(
Top,
text=
"Python - Simple Adding Value In Dictionary"
,
font=
(
'calibri'
,
16
)
)
- lbl_title.pack
(
)
- lbl_text =
Label(
Left,
text=
"Enter some text"
,
font=
(
'calibri'
,
14
)
)
- lbl_text.pack
(
)
- lbl_list =
Label(
Bottom,
text=
"List of Dictionary"
,
font=
(
'calibri'
,
14
)
)
- lbl_list.pack
(
)
- lbl_status =
Label(
Bottom,
font=
(
'calibri'
,
14
)
)
- lbl_status.pack
(
)
- #=================================ENTRY WIDGET====================================
- txt_text =
Entry(
Right,
font=
(
'calibri'
,
14
)
,
textvariable=
NAME)
- txt_text.pack
(
)
Creating the Main Function
This is where the code that contains the main functions. This code will add a new entry to the dictionary when user input some data. To do that just copy and write these blocks of code.
- #=================================METHODS=========================================
- def
Dictionary(
)
:
- global
data
- dictionary =
[
- {
"name"
: "Naruto"
}
,
- {
"name"
: "Sasuke"
}
,
- {
"name"
: "Sakura"
}
- ]
- data =
dictionary
- for
member in
data:
- temp_text =
'{0}'
.format
(
member[
'name'
]
)
- Label(
Below,
text=
temp_text)
.pack
(
anchor=
CENTER)
- def
Add(
)
:
- if
NAME.get
(
)
==
""
:
- lbl_status.config
(
text=
"Please enter something"
,
fg=
"Red"
)
- else
:
- lbl_status.config
(
text=
""
)
- data.append
(
{
"name"
: "%s"
% (
NAME.get
(
)
)
}
)
- for
widget in
Below.winfo_children
(
)
:
- widget.destroy
(
)
- for
member in
data:
- temp_text =
'{0}'
.format
(
member[
'name'
]
)
- Label(
Below,
text=
temp_text)
.pack
(
anchor=
CENTER)
- NAME.set
(
''
)
- Dictionary(
)
Initializing the Application
After finishing the function save the application as index.py. This function will run the code and check if the main is initialize properly. To do that copy the code below and paste it inside the IDLE text editor.
- #=================================INITIALIZATION==================================
- if
__name__ ==
'__main__'
:
- root.mainloop
(
)
There you have it we just created a Simple Adding Value In Dictionary Using Python. I hope that this simple tutorial help you for what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Download
You must upgrade your account or reply in the thread to view hidden text.