class Student: Student class defines common information for all students definit__(self, first=, last=, major='CIS'): self.fname =...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
class Student: """Student class defines common information for all students""" definit__(self, first="", last="", major='CIS'): self.fname = first self. lname = last self.major = major @property def fname (self): return self.. _fname.capitalize() @fname.setter def fname (self, first): if first.isalpha(): self.__fname = first self.__fname = 'Unknown else: @property def lname (self): return self._lname.capitalize() @lname.setter def lname (self, last): if last.isalpha(): self.__lname = last else: self._ 1 lname = 'Unknown' @property def major (self): return self._major.upper() @major.setter def major (self, major): if major.isalpha() and len(major) == 3: self._major = major def _str_(self): """Override the string representation of a student""" # Use the properties or you are not executing the formatting return f'{self. lname}, {self.fname} - {self.major}' class GradStudent (Student): """GradStudent inherits from Student to get first & last name def _init__(self, thesis, first="", last='', major='CIS'): """Initialize a GradStudent with first name and thesis""" super()._init_(first, last, major) self. thesis = thesis @property def thesis (self): return self.__thesis.capitalize() @thesis.setter def thesis (self, new_thesis): """Add Thesis label to entry""" self.__thesis = 'Thesis: + new_thesis def _str_(self): """Override the string representation of a student""" stu_info = super()._str_() return f'{stu_info} {self. thesis}' Learning Outcomes 1. Utilize the tkinter built-in API to create a data entry GUI 2. Implement widgets new widgets (Listbox, Radiobutton, and Frame) 3. Implement event handler functions Program Overview This program is a data entry form. Utilizing new widgets, a Combobox, Frame, Listbox, and Radiobutton to collect and display information to the user. Frame are a great way to place and group items within your Tk object aka the window. This application will allow the user to enter students (two types Student and GradStudent). We will make use of the classes we created in a previous exercise. Radio buttons will be used to select the student type while all other information will be entered in Entry widgets. One exception is the student's major will be selected using a Combobox. After all entries are made the user will click the Save button to add the student object to a list and a Listbox widget for display. The user will also have the option to double-click students in the Listbox in order to populate that student's information into the form for edits. Sample Output Student Entry Form Student Type Student First Name: Last Name: Major: Thesis: ACC T Graduate Student (Double-Click to Edit a Student) Save Student X Student Entry Form Student Type Student First Name: Last Name: Major: Thesis: Bruce Banner BDA T Graduate Student Thesis: Its all about the green 0 Save Student (Double-Click to Edit a Student) Parker, Peter - ACC Banner, Bruce-BDA Thesis: its all about the green Gordon, Flash - CIS Thesis: flash ahhhh ahhhhh Gray, Jean-CIS X Instructions & Requirements Create a project and add a module called [ASUrite]_entry_form.py. Add your name, class, and class time to Line 1. Download the student_classes.py file from course website and add to your Pycharm project. Import the following modules (Do NOT import * from ttk as it will overshadow Frame): from tkinter import * from tkinter import ttk from students import Student, GradStudent GUI SETUP Using tkinter and ttk, code create a window Tk object and add the following widgets: One Frame, name it and set the following items o bg = ' ' this sets background color o width=300 - sets width of frame o height=80 - sets height of frame o borderwidth=1 - sets thickness of border around frame o relief-SUNKEN - determines how button looks Place frame in window using grid() Frame_object.packpropagate(0) - turns off auto-sizing of the frame - 1 turns it on Label, 'Student Type' label for radio buttons is placed in Frame o Master is the Frame object name not the window Pack() label in frame Radio Buttons, for selecting between Student and GradStudent use the below options Master is Frame object bg to set background color text = 'label name' for radio button O O O O O variable= x, where x is a StringVar or IntVar shared between both radiobuttons value=v, where v is the value assigned to variable when button is clicked 'S' or 'G' if String Var or 1 or 2 if using IntVar O O command= functionRef, to be called when clicked (can also do a bind if desired) Create the 2 radio buttons with a for loop: First store the radio buttons' text and value in a dictionary variable, student_types. Secondly, in a for loop, go through all items in student_types to get the radio buttons' text and value to create a radio button at a time. Pack buttons in Frame, use side attribute to set those radio buttons to be displayed to left. 3 Entry and Label widgets for first and last name, and thesis o background-c, where c is a color as a string o justify=a, where a is alignment (LEFT, RIGHT, CENTER) width=n, where n is an integer number O textvariable=String VarObject to .set() or .get() what is in the entry box Combobox, used to select the major (you must type ttk.Combobox to access class): O values=list, list object that holds the string majors that you want selectable O textvariable=String VarObject to .set() or .get() what is selected in the box O O O width ComboboxObject.current(0) - sets default selection to first value in list Place Combobox using grid() One Button: O text=' Save Student' O command or bind to a function (your choice) O Place using grid(), grid(sticky=E) sticky will stick the button to East justification Listbox with a Label above it listing instructions O Master is window O Width O bind(' ', event_handler) will trigger function with a double left click O Place using grid() Don't forget to start mainloop() Program Development Create variables to track the following information: student_roster a list of all student objects added to listbox edit mode - True of False to determine how Save Button works edit index stores the index of the student double-clicked in listbox so we know which index to edit in both the Listbox and student_roster String Var objects for student_type, first name, last name, major, thesis Suggestions: Use bgcolor variable to set a background color and to avoid typing same color over and over Use framebgcolor variable for same reason student_types, a dictionary of text and value for radio buttons majors, a list of all majors in string format that will be used in the value attribute in the combobox widget Functions/Event Handlers: 1. Define a save_student_click. This function should execute upon clicking the Save Button. You'll want global access to all entered data. You can directly get the data from widgets or String Var objects (if you linked them using textvariable= ). Peform the following logic: If student type is GradStudent Construct GradStudent() passing data to constructor (ensure you have imported the student_classes module you downloaded and saved in your project). Else Construct a regular student passing appropriate data (first, last, major). After the above Ifedit_mode Else student_roster[edit_index] = studentObjectConstructed Above Delete student from list box at edit_index listbox.delete(index) Insert new student to listbox at edit_index - listbox.insert(index, object) Turn edit mode off or False Append new student object to student_roster list Insert new student to listbox-listbox.insert(END, object) Clear Form entries 2 Define an event handler for double-click in list box, edit_student(event). List all globals needed. Perform the below logic: Turn edit mode on edit_index = student_listbox.curselection()[0] curselection() returns a tuple and index 0 will hold the index you double-clicked within the listbox. edit_student = student_roster[edit_index] store reference to object you are editing if edit_student isinstance() of GradStudent stu_type set to the value you chose to represent this in radio buttons G or 2 Since the student is GradStudent, set thesis Entry text to edit_student.thesis Else stu_type set to the value you chose to represent this in radio buttons 'S' or 1 Toggle thesis Entry widget NORMAL/DISABLED accordingly Set all other Entry widgets to the data in edit_student object Optional Functions 3. toggle_thesis(), change the Entry widget from NORMAL to DISABLED and vice versa. 4 clear_form(), clear text of all Entry widgets Learning Points Events are linked to functions using command or bind Using bind passes an event object and using command passing nothing How to use Combobox, Frame, Listbox, and Radiobutton class Student: """Student class defines common information for all students""" definit__(self, first="", last="", major='CIS'): self.fname = first self. lname = last self.major = major @property def fname (self): return self.. _fname.capitalize() @fname.setter def fname (self, first): if first.isalpha(): self.__fname = first self.__fname = 'Unknown else: @property def lname (self): return self._lname.capitalize() @lname.setter def lname (self, last): if last.isalpha(): self.__lname = last else: self._ 1 lname = 'Unknown' @property def major (self): return self._major.upper() @major.setter def major (self, major): if major.isalpha() and len(major) == 3: self._major = major def _str_(self): """Override the string representation of a student""" # Use the properties or you are not executing the formatting return f'{self. lname}, {self.fname} - {self.major}' class GradStudent (Student): """GradStudent inherits from Student to get first & last name def _init__(self, thesis, first="", last='', major='CIS'): """Initialize a GradStudent with first name and thesis""" super()._init_(first, last, major) self. thesis = thesis @property def thesis (self): return self.__thesis.capitalize() @thesis.setter def thesis (self, new_thesis): """Add Thesis label to entry""" self.__thesis = 'Thesis: + new_thesis def _str_(self): """Override the string representation of a student""" stu_info = super()._str_() return f'{stu_info} {self. thesis}' Learning Outcomes 1. Utilize the tkinter built-in API to create a data entry GUI 2. Implement widgets new widgets (Listbox, Radiobutton, and Frame) 3. Implement event handler functions Program Overview This program is a data entry form. Utilizing new widgets, a Combobox, Frame, Listbox, and Radiobutton to collect and display information to the user. Frame are a great way to place and group items within your Tk object aka the window. This application will allow the user to enter students (two types Student and GradStudent). We will make use of the classes we created in a previous exercise. Radio buttons will be used to select the student type while all other information will be entered in Entry widgets. One exception is the student's major will be selected using a Combobox. After all entries are made the user will click the Save button to add the student object to a list and a Listbox widget for display. The user will also have the option to double-click students in the Listbox in order to populate that student's information into the form for edits. Sample Output Student Entry Form Student Type Student First Name: Last Name: Major: Thesis: ACC T Graduate Student (Double-Click to Edit a Student) Save Student X Student Entry Form Student Type Student First Name: Last Name: Major: Thesis: Bruce Banner BDA T Graduate Student Thesis: Its all about the green 0 Save Student (Double-Click to Edit a Student) Parker, Peter - ACC Banner, Bruce-BDA Thesis: its all about the green Gordon, Flash - CIS Thesis: flash ahhhh ahhhhh Gray, Jean-CIS X Instructions & Requirements Create a project and add a module called [ASUrite]_entry_form.py. Add your name, class, and class time to Line 1. Download the student_classes.py file from course website and add to your Pycharm project. Import the following modules (Do NOT import * from ttk as it will overshadow Frame): from tkinter import * from tkinter import ttk from students import Student, GradStudent GUI SETUP Using tkinter and ttk, code create a window Tk object and add the following widgets: One Frame, name it and set the following items o bg = ' ' this sets background color o width=300 - sets width of frame o height=80 - sets height of frame o borderwidth=1 - sets thickness of border around frame o relief-SUNKEN - determines how button looks Place frame in window using grid() Frame_object.packpropagate(0) - turns off auto-sizing of the frame - 1 turns it on Label, 'Student Type' label for radio buttons is placed in Frame o Master is the Frame object name not the window Pack() label in frame Radio Buttons, for selecting between Student and GradStudent use the below options Master is Frame object bg to set background color text = 'label name' for radio button O O O O O variable= x, where x is a StringVar or IntVar shared between both radiobuttons value=v, where v is the value assigned to variable when button is clicked 'S' or 'G' if String Var or 1 or 2 if using IntVar O O command= functionRef, to be called when clicked (can also do a bind if desired) Create the 2 radio buttons with a for loop: First store the radio buttons' text and value in a dictionary variable, student_types. Secondly, in a for loop, go through all items in student_types to get the radio buttons' text and value to create a radio button at a time. Pack buttons in Frame, use side attribute to set those radio buttons to be displayed to left. 3 Entry and Label widgets for first and last name, and thesis o background-c, where c is a color as a string o justify=a, where a is alignment (LEFT, RIGHT, CENTER) width=n, where n is an integer number O textvariable=String VarObject to .set() or .get() what is in the entry box Combobox, used to select the major (you must type ttk.Combobox to access class): O values=list, list object that holds the string majors that you want selectable O textvariable=String VarObject to .set() or .get() what is selected in the box O O O width ComboboxObject.current(0) - sets default selection to first value in list Place Combobox using grid() One Button: O text=' Save Student' O command or bind to a function (your choice) O Place using grid(), grid(sticky=E) sticky will stick the button to East justification Listbox with a Label above it listing instructions O Master is window O Width O bind(' ', event_handler) will trigger function with a double left click O Place using grid() Don't forget to start mainloop() Program Development Create variables to track the following information: student_roster a list of all student objects added to listbox edit mode - True of False to determine how Save Button works edit index stores the index of the student double-clicked in listbox so we know which index to edit in both the Listbox and student_roster String Var objects for student_type, first name, last name, major, thesis Suggestions: Use bgcolor variable to set a background color and to avoid typing same color over and over Use framebgcolor variable for same reason student_types, a dictionary of text and value for radio buttons majors, a list of all majors in string format that will be used in the value attribute in the combobox widget Functions/Event Handlers: 1. Define a save_student_click. This function should execute upon clicking the Save Button. You'll want global access to all entered data. You can directly get the data from widgets or String Var objects (if you linked them using textvariable= ). Peform the following logic: If student type is GradStudent Construct GradStudent() passing data to constructor (ensure you have imported the student_classes module you downloaded and saved in your project). Else Construct a regular student passing appropriate data (first, last, major). After the above Ifedit_mode Else student_roster[edit_index] = studentObjectConstructed Above Delete student from list box at edit_index listbox.delete(index) Insert new student to listbox at edit_index - listbox.insert(index, object) Turn edit mode off or False Append new student object to student_roster list Insert new student to listbox-listbox.insert(END, object) Clear Form entries 2 Define an event handler for double-click in list box, edit_student(event). List all globals needed. Perform the below logic: Turn edit mode on edit_index = student_listbox.curselection()[0] curselection() returns a tuple and index 0 will hold the index you double-clicked within the listbox. edit_student = student_roster[edit_index] store reference to object you are editing if edit_student isinstance() of GradStudent stu_type set to the value you chose to represent this in radio buttons G or 2 Since the student is GradStudent, set thesis Entry text to edit_student.thesis Else stu_type set to the value you chose to represent this in radio buttons 'S' or 1 Toggle thesis Entry widget NORMAL/DISABLED accordingly Set all other Entry widgets to the data in edit_student object Optional Functions 3. toggle_thesis(), change the Entry widget from NORMAL to DISABLED and vice versa. 4 clear_form(), clear text of all Entry widgets Learning Points Events are linked to functions using command or bind Using bind passes an event object and using command passing nothing How to use Combobox, Frame, Listbox, and Radiobutton
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Discuss the interface between Purchasing and Supply Management and Logistics Management specifically with respect to selection of a third party logistics provider, analysis of the total cost of...
-
In 2015, Chaya Corporation, an accrual basis, calendar year taxpayer, provided services to clients and earned $25,000. The clients signed notes receivable to Chaya that have a fair market value of...
-
Find the z value in each of the following cases, (a) P[Z < z] = .1762 (b) P[Z > z] = .10 (c) P[-z < Z < z] = .954 (d) P[-.6 < Z < z] = .50
-
Pick up the correct sentence out of the following: (a) Minimum boiling azeotropes may be formed if a solution exhibits very small positive deviation from ideal behaviour (b) Maximum boiling...
-
Financial information is presented here for two companies. Instructions(a) Fill in the missing amounts. Show all computations.(b) Calculate the profit margin ratio and the gross profit rate for each...
-
What are the underlying mechanisms of organizational learning and knowledge management, and how do they contribute to sustained competitive advantage in rapidly changing environments?
-
The following is Edge Sports Repair Shop's trial balance at September 30, 2014, the company's fiscal year end: Additional information: 1. Service revenue earned but not recorded at September 30,...
-
Find the equation of the line through (-1,-2) which is perpendicular to the line y = 9. Give your answer in the form y = mx + b. Provide your answer below:
-
Which graphical tool commonly used in project management is also very useful in shop-floor control?
-
How does attribution theory allow managers to justify workers behaviors?
-
What are common methods to measure a persons attitude?
-
What do we generally call an area in a business where productive resources are organized and work is completed?
-
Why is stereotyping so problematic for the healthcare industry?
-
I. What would you do? 1. You overhear a conversation that sounds like your best friend is about to be fired from his job. 2. You overhear your mother talking to her sister on the phone. She is...
-
Place a tick in the appropriate grid to identify the balance that would be brought down in each of the following named accounts, in the books of Rizwy Mohamed: (a) In the Cash account: if Rizwy...
-
A new county hospital is attempting to determine whether it needs to add a particular specialist to its staff. Five percent of the general hospital population in the county contracts the illness the...
-
The Donnor meat processing firm produces wieners from four ingredients: chicken, beef, pork, and a cereal additive. The firm produces three types of wieners: regular, beef, and all-meat. The company...
-
The College Avenue Sub Shop is located in a small college town. Virtually all of its phone delivery orders are in the evening, between 5:00 P.M. and 1:00 A.M., so the shop has a delivery person for...
-
Fill in the Blank. For a shaft carrying masses \(m_{1}, m_{2}, \ldots\), Rayleigh's method gives the natural frequency as \[\omega=\left\{\frac{g\left(m_{1} w_{1}+m_{2} w_{2}+\cdots ight)}{m_{1}...
-
True or False. In the matrix iteration method, any computational error will not yield incorrect results.
-
Rayleigh's method a. Finds the natural frequencies and mode shapes of the system, one at a time, using several trial values for each frequency. b. Finds all the natural frequencies using trial...
Study smarter with the SolutionInn App