-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
142 lines (114 loc) · 4.62 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Lable Widgets
To add a label to our previous example,
we will create a label using the label class like this:
-> lbl = Label(window, text="Hello")
HANDLE THE BUTTON CLICK EVENT
First we write the function that we need to execute when the button is clicked
Then we will wire it the button by specifing the finction inside the button
GET INPUT USING ENTRY CLASS
We can create a textbox using Tkinter Entry like this:
txt = Entry(windo, width=10)
SET FOCUS TO THE ENTRY WIDGETS
All we need to do is to use the .focus() keyword
#CREATE A SIMPLECALCULATOR2
1. The title of the calculator will be your name
2. The background color should be green
3. The size of the app should be 400 by 300
4. For each button indicate a symbol eg addition -> +
5. Change the location of the buttons following this procedure
add was c=0,r=0 -> c=0,r=4
subtraction was c=0,r=4 -> c=0,r=3
Multiplication was c=1,r=3 -> c=1,r=4
division was c=1,r=4 -> c=1,r=3
TRY AND EXCEPT
The try block let you test a block of code for errors
The except block lets you handle the errors
The finally block lets you execute code, regardless of the result of the try and
except clocks
Exception Handling
When errors occurs, or exception as we call it, Python will normally stop and generate
an error message. These execptions can be handled using the try statement
MessageBox Widget
It is used to display the message boxes in the python applications.
messagebox.Fuction_Name(title, message[, options])
1.Write a function method1() such that it can accept
a variable length of argument and print all arguments value
2. Write a function calculation() such that it can accept two
variables and calculate the multiplication and division of them.
3. Create a function showStudent() in such a way that it should
accept student name, and their age and display both.
4. Print the numbers between 50 and 200 using while loop
5. Given a list, iterate it, and display numbers divisible by 4. HINT -> The modulus should be 0 if
the number is divisible by four.
Test two:
1. Write code to display numbers from 10 to 1 using for loop in decending order
2. Given a number count the total number of digits in that number
3. Write a program to display all odd numbers within range(80)
4. Use a loop to display elements from a given list that are
present at even index positions
5. Given a two list of numbers create a new list such that new list should contain only odd
numbers from the first list and even numbers from the second list
list1 = [10, 20, 23, 11, 17]
list 2 = [13, 43, 24, 36, 12] #Use the append function
Test Three:
1. Use a while loop to print the following pattern
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
2. Create a python function that generates a Python list of all the even numbers between 4 to 30
3. Create a function that returns the largest item from the given list
aList = [4, 6, 8, 24, 12, 2]
4. Create a Vehicle class with max_speed and mileage instance attributes
5. Create a Vehicle class without any variables and methods
Test 4
1. Iterate a given list and count the occurrence of each element
2. Given a list, iterate it, and display numbers divisible by five,
and if you find a number greater than 150, stop the loop iteration.
3. Display a message “Done” after successful execution of for loop
4. Write a program to display all prime numbers within a range
5. Print the following pattern
Fizz Buzz
Write a program that take in a number. If the number is divisible
by 3 it prints fizz if the the number is divisible by 5 it prints
buzz otherwise it prints the number.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Test 5
1. Remove empty strings from the list of strings
2. Given a Python list of numbers. Turn every item of a list into its square
3. Given two strings, s1 and s2, create a new string by appending s2 in the middle of s1
4. Create a python function that generates a Python list of all the even numbers between 4 to 30
5. Create a function that returns the largest item from the given list
COMBO WIDGET
To add a combo widget, you cn use the combo class ttk library
from tkinter.ttk import *
combo = Combobox(window)
combo.get()
CHECKBUTTON WIDGET
chk = Checkbutton(window, text='Choose')
RADIO BUTTON
rad1 = Radiobutton(window,text='First', value=1)
SCROLLED TEXT WIDGET
from tkinter import scrolledtext
txt = scrolledtext.ScrolledText(window,width=40,height=10)
MessageBox
from tkinter import messagebox
messagebox.showinfo('Message title','Message content')
SPINBOX
spin = Spinbox(window, from_=0, to=100)
MENUBAR
menu.add_cascade(label='File', menu=new_item)