Open mrafert1 opened 1 year ago
import tkinter from tkinter import ttk
def submit_profile(): name = name_entry.get() age = age_entry.get() location = location_entry.get() print ("Name:", name, "--- Age:", age, "--- Location:", location) primary = primary_combobox.get() secondary = secondary_combobox.get() skill = skill_combobox.get() print ("Primary Instrument:", primary, "--- Secondary Instrument:", secondary, "--- Skill Level:", skill) favorite = favorite_combobox.get() style = style_combobox.get() print ("I am looking for a", favorite, "band. I am also interested in the", style, "genre.")
def exit_program(): window.destroy()
def clear_fields(): name_entry.delete (0, tkinter.END) age_entry.delete (0, tkinter.END) location_entry.delete (0, tkinter.END) primary_combobox.delete (0, tkinter.END) secondary_combobox.delete (0, tkinter.END) skill_combobox.delete (0, tkinter.END) favorite_combobox.delete (0, tkinter.END) style_combobox.delete (0, tkinter.END)
window = tkinter.Tk() window.title ("BandFinder") window.geometry ("800x400")
frame = tkinter.Frame(window) frame.pack()
basic_info_frame = tkinter.LabelFrame(frame, text = "Basic Information") basic_info_frame.grid (row = 0, column = 0, sticky = "news", padx =10, pady=10)
name_label = tkinter.Label(basic_info_frame, text = "Name: ") name_label.grid (row = 0, column = 0) age_label = tkinter.Label(basic_info_frame, text = "Age: ") age_label.grid (row = 0, column = 1) location_label = tkinter.Label(basic_info_frame, text = "Location: ") location_label.grid (row = 0, column = 2)
name_entry = tkinter.Entry(basic_info_frame) age_entry = tkinter.Entry(basic_info_frame) location_entry = tkinter.Entry(basic_info_frame) name_entry.grid (row = 1, column = 0) age_entry.grid (row = 1, column = 1) location_entry.grid (row = 1, column = 2)
for widget in basic_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
instrument_info_frame = tkinter.LabelFrame (frame, text = "Instrument Information") instrument_info_frame.grid (row = 1, column = 0, sticky = "news", padx = 10, pady = 10)
primary_label = tkinter.Label (instrument_info_frame, text = "Primary Instrument") primary_combobox = ttk.Combobox (instrument_info_frame, values = ["Guitar", "Bass", "Piano", "Drums", "Vocals", "Harmonica", "Percussion", "Horns"]) primary_label.grid ( row = 0, column = 0) primary_combobox.grid (row = 1, column = 0)
secondary_label = tkinter.Label (instrument_info_frame, text = "Secondary Instrument") secondary_combobox = ttk.Combobox (instrument_info_frame, values = ["Guitar", "Bass", "Piano", "Drums", "Vocals", "Harmonica", "Percussion", "Horns"]) secondary_label.grid (row = 0, column = 1) secondary_combobox.grid (row = 1, column = 1)
skill_label = tkinter.Label (instrument_info_frame, text = "Skill Level") skill_combobox = ttk.Combobox (instrument_info_frame, values = ["Beginner", "Intermediate", "Pro"]) skill_label.grid (row = 0, column = 2) skill_combobox.grid (row = 1, column = 2)
for widget in instrument_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
genre_info_frame = tkinter.LabelFrame (frame, text = "Genre Information") genre_info_frame.grid (row = 2, column = 0, sticky = "news", padx =10, pady = 10)
favorite_label = tkinter.Label (genre_info_frame, text = "What's Type of Band Do You Want To Start?") favorite_combobox = ttk.Combobox (genre_info_frame, value = ["Rock", "Hip Hop", "Funk", "R&B", "Reggae", "Jazz", "Blues", "Classical", "Other"]) favorite_label.grid (row = 0, column =0) favorite_combobox.grid (row = 1, column = 0)
style_label = tkinter.Label (genre_info_frame, text = "What Other Genre's Are You Interested In?") style_combobox = ttk.Combobox (genre_info_frame, value = ["Rock", "Hip Hop", "Funk", "R&B", "Reggae", "Jazz", "Blues", "Classical", "Other"]) style_label.grid (row = 0, column = 1) style_combobox.grid (row = 1, column = 1)
for widget in genre_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
button_frame = tkinter.LabelFrame(frame) button_frame.grid (row = 3, column = 0, sticky = "news", padx = 10, pady = 10)
submit_button = tkinter.Button (button_frame, text = "Submit Your Profile", command = submit_profile) submit_button.grid (row = 0, column = 1, padx = 10, pady = 10)
exit_button = tkinter.Button (button_frame, text = "Exit Program", command = exit_program) exit_button.grid (row = 0, column = 2, padx = 10, pady = 10)
clear_button = tkinter.Button (button_frame, text = "Clear Fields", command = clear_fields) clear_button.grid (row = 0, column = 0, padx = 10, pady = 10)
for widget in button_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
window.mainloop()
Program Name: BandFinder
Author: Max Rafert
This program will allow a user to create a profile that could be sent to a database of other profiles to find like minded band members.
import tkinter from tkinter import ttk
Submit function allows user to submit code
def submit_profile(): name = name_entry.get() age = age_entry.get() location = location_entry.get() print ("Name:", name, "--- Age:", age, "--- Location:", location) primary = primary_combobox.get() secondary = secondary_combobox.get() skill = skill_combobox.get() print ("Primary Instrument:", primary, "--- Secondary Instrument:", secondary, "--- Skill Level:", skill) favorite = favorite_combobox.get() style = style_combobox.get() print ("I am looking for a", favorite, "band. I am also interested in the", style, "genre.")
Exit function will allow exit button to close program
def exit_program(): window.destroy()
Clear function allows user to clear all fields and begin again.
def clear_fields(): name_entry.delete (0, tkinter.END) age_entry.delete (0, tkinter.END) location_entry.delete (0, tkinter.END) primary_combobox.delete (0, tkinter.END) secondary_combobox.delete (0, tkinter.END) skill_combobox.delete (0, tkinter.END) favorite_combobox.delete (0, tkinter.END) style_combobox.delete (0, tkinter.END)
Initial Window
Initital window is created and set to frame mode in order to create a well organized UI.
window = tkinter.Tk() window.title ("BandFinder") window.geometry ("800x400")
frame = tkinter.Frame(window) frame.pack()
basic info frame
Basic frame is first segment of user entered basic information.
basic_info_frame = tkinter.LabelFrame(frame, text = "Basic Information") basic_info_frame.grid (row = 0, column = 0, sticky = "news", padx =10, pady=10)
name_label = tkinter.Label(basic_info_frame, text = "Name: ") name_label.grid (row = 0, column = 0) age_label = tkinter.Label(basic_info_frame, text = "Age: ") age_label.grid (row = 0, column = 1) location_label = tkinter.Label(basic_info_frame, text = "Location: ") location_label.grid (row = 0, column = 2)
name_entry = tkinter.Entry(basic_info_frame) age_entry = tkinter.Entry(basic_info_frame) location_entry = tkinter.Entry(basic_info_frame) name_entry.grid (row = 1, column = 0) age_entry.grid (row = 1, column = 1) location_entry.grid (row = 1, column = 2)
for widget in basic_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
instrument info frame
Instrument frame is a series of comboboxes that allows the user to select their prefered instruments and skill level.
instrument_info_frame = tkinter.LabelFrame (frame, text = "Instrument Information") instrument_info_frame.grid (row = 1, column = 0, sticky = "news", padx = 10, pady = 10)
primary_label = tkinter.Label (instrument_info_frame, text = "Primary Instrument") primary_combobox = ttk.Combobox (instrument_info_frame, values = ["Guitar", "Bass", "Piano", "Drums", "Vocals", "Harmonica", "Percussion", "Horns"]) primary_label.grid ( row = 0, column = 0) primary_combobox.grid (row = 1, column = 0)
secondary_label = tkinter.Label (instrument_info_frame, text = "Secondary Instrument") secondary_combobox = ttk.Combobox (instrument_info_frame, values = ["Guitar", "Bass", "Piano", "Drums", "Vocals", "Harmonica", "Percussion", "Horns"]) secondary_label.grid (row = 0, column = 1) secondary_combobox.grid (row = 1, column = 1)
skill_label = tkinter.Label (instrument_info_frame, text = "Skill Level") skill_combobox = ttk.Combobox (instrument_info_frame, values = ["Beginner", "Intermediate", "Pro"]) skill_label.grid (row = 0, column = 2) skill_combobox.grid (row = 1, column = 2)
for widget in instrument_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
genre info frame
Genre frame allows a user to select from comboboxes which genre of band they want to start as well as listing other genre's they may be interested in.
genre_info_frame = tkinter.LabelFrame (frame, text = "Genre Information") genre_info_frame.grid (row = 2, column = 0, sticky = "news", padx =10, pady = 10)
favorite_label = tkinter.Label (genre_info_frame, text = "What's Type of Band Do You Want To Start?") favorite_combobox = ttk.Combobox (genre_info_frame, value = ["Rock", "Hip Hop", "Funk", "R&B", "Reggae", "Jazz", "Blues", "Classical", "Other"]) favorite_label.grid (row = 0, column =0) favorite_combobox.grid (row = 1, column = 0)
style_label = tkinter.Label (genre_info_frame, text = "What Other Genre's Are You Interested In?") style_combobox = ttk.Combobox (genre_info_frame, value = ["Rock", "Hip Hop", "Funk", "R&B", "Reggae", "Jazz", "Blues", "Classical", "Other"]) style_label.grid (row = 0, column = 1) style_combobox.grid (row = 1, column = 1)
for widget in genre_info_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
Button Frame
Buttom frame consists of the three buttons that will make this program funciton. The first being a submit button which will submit the data,
the second being an exit button that will close the program, and the third being a clear button that will clear all fields for a quick reset of data entry.
button_frame = tkinter.LabelFrame(frame) button_frame.grid (row = 3, column = 0, sticky = "news", padx = 10, pady = 10)
Submit Button
submit_button = tkinter.Button (button_frame, text = "Submit Your Profile", command = submit_profile) submit_button.grid (row = 0, column = 1, padx = 10, pady = 10)
Exit button
exit_button = tkinter.Button (button_frame, text = "Exit Program", command = exit_program) exit_button.grid (row = 0, column = 2, padx = 10, pady = 10)
Clear button
clear_button = tkinter.Button (button_frame, text = "Clear Fields", command = clear_fields) clear_button.grid (row = 0, column = 0, padx = 10, pady = 10)
for widget in button_frame.winfo_children(): widget.grid_configure (padx = 10, pady = 5)
window.mainloop()