Jan-23-2023, 09:47 AM
(This post was last modified: Jan-23-2023, 11:38 PM by Yoriz.
Edit Reason: Added code tags, Title
)
I want to add a code to the "Save" button to save the data entered . Also, I want when you click on "Back" button, it go to main menu. At the same time, I want to present check the data entry on "Student Name" text box. Below is the code:
from tkinter import * top = Tk() top.geometry("450x500") def open_text(): text_file = open("test.txt", "r") content = text_file.read() my_text_box.insert(END, content) text_file.close() def save_text(): text_file = open("test.txt", "w") text_file.write(my_text_box.get(1.0, END)) text_file.close() def main(): Messageforyou = Label(top, text = "Park Wood School - Students Details").place(x = 100, y = 20) # the label for user_name user_name = Label(top, text = "Pupil ID").place(x = 40, y = 60) # the label for user_password user_password = Label(top, text = "First Name").place(x = 40, y = 100) user_Surname = Label(top, text = "Surname").place(x = 40, y = 140) user_Form_Class = Label(top, text = "Form Class").place(x = 40, y = 180) user_password = Label(top, text = "DOB").place(x = 40, y = 220) submit_button = Button(top, text = "Add Pupil").place(x = 100, y = 250) my_text_box = Button(top, text = "Save").place(x = 100, y = 300) submit_button = Button(top, text = "Back").place(x = 100, y = 350) Messageforyou = Label(top, text = "Please Enter Pupils Details").place(x = 100, y = 400) user_name_input_area = Entry(top, width = 30).place(x = 110, y = 60) user_password_entry_area = Entry(top, width = 30).place(x = 110, y = 100) user_password_entry_area = Entry(top, width = 30).place(x = 110, y = 140) user_name_input_area = Entry(top, width = 30).place(x = 110, y = 180) user_name_input_area = Entry(top, width = 30).place(x = 110, y = 220) # Creating a text box widget my_text_box = Text(win, height=10, width=20) my_text_box.pack() open_btn = Button(win, text="Open Text File", command=open_text) open_btn.pack() # Create a button to save the text save = Button(win, text="Save File", command=save_text) save.pack() win.mainloop() top.mainloop()
buran write Jan-23-2023, 10:01 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Please, don't hijack other member's threads
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Please, don't hijack other member's threads