Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python: tkinter / ctkinter - values not populating from entries

$
0
0

I am trying to get values and create a Student object, but the values are not populating.

Here is my Student class:

class Student:    def __init__(self, firstName=None, lastName=None, dateOfBirth=None, age=None, schoolName=None, schoolId=None, addressLine=None, city=None, zip=None, language=None):        self.firstName = firstName        self.lastName = lastName        self.dateOfBirth = dateOfBirth        self.age = age        self.schoolName = schoolName        self.schoolId = schoolId        self.addressLine = addressLine        self.city = city        self.zip = zip        self.language = language

My Main GUI Frame/application that is to gather student details to create a record. Once the details are entered I want to create an instance of a student using the class and save the data (have not gotten to saving the data part as I cant get the data to print).

import sysimport tkinterimport customtkinter as ctkimport selffrom tkcalendar import *from datetime import date, datetimefrom Student import *# Theme set-upctk.set_appearance_mode("dark")ctk.set_default_color_theme("dark-blue")# GUI set-upmainMenu = ctk.CTk()mainMenu.title("GUI Application")mainMenu.geometry("800x500")# Frame set-upmainMenuFrame = ctk.CTkFrame(master=mainMenu)mainMenuFrame.pack(pady=20, padx=60, fill="both", expand=True)ageSelection = tkinter.StringVar()#Functionsdef exitProgram():    sys.exit()def getAge(today, dob, student):    print(today)    print(dob)    dob_result = str(dob)    dob_data = dob_result.split("-")    year = int(dob_data[0])    month = int(dob_data[1])    day = int(dob_data[2])    print(year)    print(month)    print(day)    age = (today - date(year, month, day)).days    age = age / 365    print(age)    age = round(age)    ageSelection = round(age)    print(round(age))def createStudentRecord(firstName, lastName, dob, schoolName, schoolId, addressLine, city, zip, language):    s1 = Student(firstName, lastName,dob,schoolName,schoolId,addressLine, city, zip, language)    print(firstName)    print(lastName)    print(dob)    print(schoolId)    print(addressLine)    print(city)    print(zip)    print(language)def loadStudentInfoView():    # Remove main menu frame    mainMenuFrame.pack_forget()    studentInfoFrame = ctk.CTkFrame(master=mainMenu)    studentInfoFrame.grid(row=0, column=0)    # Student Info set-up    #First & Last Name    firstNameLabel = ctk.CTkLabel(master=studentInfoFrame, text="First Name", font=('Calibri',20))    firstNameLabel.grid(row=0, column=0)    firstNameText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=150)    firstNameText.grid(row=1, column=0, padx=20)    firstName = str(firstNameText.get())    lastNameLabel = ctk.CTkLabel(master=studentInfoFrame, text="Last Name", font=('Calibri', 20))    lastNameLabel.grid(row=0, column=1)    lastNameText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=150)    lastNameText.grid(row=1, column=1, padx=20)    # Birth date (Calendar), automatically calculate age    #DOB drop down    dobLabel = ctk.CTkLabel(master=studentInfoFrame, text="DOB", font=('Calibri', 20))    dobLabel.grid(row=0, column=2)    calPicker = DateEntry(studentInfoFrame, selectmode="day", year=2014, month=2, day=7, date_pattern="yyyy-mm-dd")    calPicker.grid(row=1, column=2)    #School Details    schoolNameLabel = ctk.CTkLabel(master=studentInfoFrame, text="School Name", font=('Calibri', 20))    schoolNameLabel.grid(row=2, column=0)    schoolNameText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=150)    schoolNameText.grid(row=3, column=0, padx=20)    #School ID    schoolIdLabel = ctk.CTkLabel(master=studentInfoFrame, text="School ID", font=('Calibri', 20))    schoolIdLabel.grid(row=2, column=1)    schoolIdText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=70)    schoolIdText.grid(row=3, column=1, padx=20)    #Address Line 1 & 2, City, State, Zip    addressLineLabel = ctk.CTkLabel(master=studentInfoFrame, text="Address Line", font=('Calibri', 20))    addressLineLabel.grid(row=5, column=0)    addressLineText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=300)    addressLineText.grid(row=6, column=0, padx=20)    cityLabel = ctk.CTkLabel(master=studentInfoFrame, text="City", font=('Calibri', 20))    cityLabel.grid(row=5, column=1)    cityText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=120)    cityText.grid(row=6, column=1, padx=20)    stateLabel = ctk.CTkLabel(master=studentInfoFrame, text="State (dropdown)", font=('Calibri', 20))    stateLabel.grid(row=5, column=2)    stateText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=50)    stateText.grid(row=6, column=2, padx=20)    zipLabel = ctk.CTkLabel(master=studentInfoFrame, text="Zip Code", font=('Calibri', 20))    zipLabel.grid(row=5, column=3)    zipText = ctk.CTkEntry(master=studentInfoFrame, height=30, width=50)    zipText.grid(row=6, column=3, padx=20)    #Language    # Create Record Button    createRecordButton = ctk.CTkButton(master=studentInfoFrame, text="Create Student Record", command=lambda : createStudentRecord(firstName, lastNameText, calPicker, schoolNameText,                                                                                                                          schoolIdText, addressLineText, cityText, zipText, language=None))    createRecordButton.grid(row=8, column=1, pady=80)# Main Menu Layout# Title Labeltitle = ctk.CTkLabel(master = mainMenuFrame, text="LSSP Helper", font=('Arial', 32))title.pack(pady=12, padx=10)# Text Labeltitle2 = ctk.CTkLabel(master = mainMenuFrame, text="Can you")title2.pack(pady=12, padx=10)# Text Labeltitle3 = ctk.CTkLabel(master = mainMenuFrame, text="please")title3.pack(pady=12, padx=10)# Text Labeltitle4 = ctk.CTkLabel(master = mainMenuFrame, text="HELLLLLLLLLLLLLLLLLLLLLLLLLLLLLP!?!?!?!?!")title4.pack(pady=12, padx=10)# Button 1button1 = ctk.CTkButton(master = mainMenuFrame, text="Create New Student Record", command=loadStudentInfoView)button1.pack(pady=12, padx=10)# Button 2button2 = ctk.CTkButton(master = mainMenuFrame, text="Resume Student Record")button2.pack(pady=12, padx=10)# Button 3button3 = ctk.CTkButton(master = mainMenuFrame, text="Observation Form")button3.pack(pady=12, padx=10)# Exit ButtonexitButton = ctk.CTkButton(master = mainMenuFrame, text="Exit", command=exitProgram)exitButton.pack(pady=12, padx=10)mainMenu.mainloop()

Output from function, createStudentRecord, comes out as ctk data??? :

# empty value as I tried to use text.get() method.!ctkframe2.!ctkentry2.!ctkframe2.!dateentry.!ctkframe2.!ctkentry4.!ctkframe2.!ctkentry5.!ctkframe2.!ctkentry6.!ctkframe2.!ctkentry8None

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>