Likewise, since the labels are blue, we can derive a BlueLabel class: # all these labels are blue class BlueLabel(Label): def _init_(self, root, nm): super()._init_(root, text=nm, fg= 'blue') # derived button is always 8 chars wide # with simplified enable and disable methods class DButton(Button): def _init_(self, master=None, **kwargs): super()._init_(master, width=8, **kwargs) def enable(self): self = NORMAL def disable(self): self = DISABLED The buttons are now all the same width as you can see here. We’ll also create the convenience methods enable and disable which are easier to type. What we need to do is to create a derived button that has a fixed width of, say, 8 characters. You can also clear the name fields and reset the list to its original six names as shown below:īecause the buttons are no larger than needed by the text you put into them. There are also buttons to add, delete, and update the names. Our design consists of a listbox of names on the right side, and entry fields for name and phone number on the left side. Then we create a NameList class which holds an array of Person objects and allows you to add more and delete them one by one if you need to: # a collection of address entries class NameList(): def _init_(self, narray): self.names = for nm in narray: p = Person(nm) (p) # add a person def add(self, person): (person) # delete a person def delete(self, index): (index) Visual design Of course, it could contain a street and E-mail address as well and would work the same way. # One person class Person(): def _init_(self, nameArray): self.name = nameArray self.phone = nameArray We create a Person class which stores the name and phone number. contactlist =, ,, ,, , ] Classes we use for the data It could be a dictionary or a database: the code would be much the same. Our basic data is just an array of two-element arrays. In this article we take a design proposed by Data Flair and expand on it by using Python layout managers and some simple classes to organize the program. It should display a list of names and allow you to view the details of any individual, as well as being able to add, edit to update entries. Print("".It is not uncommon to propose an exercise in Python to construct an address book display. Num = int(input("Enter the total number of contacts you want to save: "))Ĭontact_number = int(input("Contact Number: ")) It is a fundamental program that shows how simple logic works using arrays, loops, and conditional statements.Īn example of a Contact book in Python: names = This Python contact book program saves user input as a contact book description and retrieves it as search results. Python String Programs Python Hello World Program Palindrome Program in Python Python Program to Remove Characters From a String Python Program to Convert Int to String Concatenate Strings in Python Python Program to Compare Strings Python Program to Generate Strong Password Python Program for Text Wrapping Python Program to Trim Whitespace From a String Python Program to Find the ASCII Value of a Character Python Variable Programs Python Program to Swap Two Variables Using a Temporary Variable Python Loop Programs Python Program to Creating an Equilateral Triangle (Pyramid Pattern) Python Program to Print Half Pyramid Using Alphabets Python Function Programs Python Program to Automatically Correct Spelling Python Program to Create Dummy Data Real Time Currency Converter in Python Python Array Programs Python Program to Convert Two Lists Into a Dictionary Python Number Programs Python Program to Check Even or Odd Number Python Program to Find Largest of Three Numbers Using If Fibonacci Series in Python Python Program to Add Two Numbers Python Program to Add Two Given Numbers Python Program to Generate Random Lottery Numbers Python Program to Find Square Root of Positive Numbers Python Program to Calculate the Area of a Triangle Python Program to Check Prime Number Python Program to Calculate BMI Python Program to Find Factorial of a Number Using a Loop Python Program to Generate a Random Number Python Program to Check Leap Year Python Program to Find the Sum of Natural Numbers Python Program to Convert Kilometers to Miles Simple Calculator Program in Python Python File I/O Programs Python Program to Get Country Information Python Program to Create a Contact Book Python Graphics Programs Python Program to Create Chessboard Using Matplotlib Python Program to Create Pie Charts Using Matplotlib Python Program to Create Bar Graph Using Matplotlib Python Program to Create Radar Plot Using Plotly Express report this ad report this ad
0 Comments
Leave a Reply. |