I have a database that includes students' information. In the middle of the program, I need a Tkinter window to be open. How should I open a GUI window in the middle of a Python program?! The window must include a search box (Entry) by n_number (dictionary value) to show the name (dictionary key related to the entered n_number) of the student and a list of all students. At the same time that I can search by n_number, I need the list of all students, so I can click on each name and see the courses he/she got. I don't know how can I make a clickable list in Tkinter.
...
from tkinter import *
class Student:
def __init__(self):
self.name = ""
self.n_number = None
self.courses = {}
self.students = {}
def add_stu(self, name, n_number):
self.students[name] = n_number
def find_stu(self, n_number):
return list(self.students.keys())[list(self.students.values()).index(n_number)]
def add_course(self, cname, score):
self.courses[cname] = score
...
CodePudding user response:
Just .destroy
your root element after you get what you want from user, consider following simple example:
from tkinter import *
user_input = ""
def get_and_destroy():
global user_input
user_input = entry.get()
root.destroy()
print("Before tkinter")
root = Tk()
entry = Entry(root)
entry.pack()
btn = Button(root, text="Go", command=get_and_destroy)
btn.pack()
mainloop()
print("After tkinter")
print("User typed:",user_input)
As you might observe destroy
-ing cause breaking from mainloop()
CodePudding user response:
Create a function with the Tkinter
and call it when you need the pop up.
CodePudding user response:
To add another window you do Tk()
from tkinter import *
wn = Tk()
wn.title('Window 1')
window = Tk()
window.title('Window2')