Reputation: 13
I created a button and defined it a messagebox.showinfo()
on successfully running and when the OK button is pressed it takes me to the first (Main) Page rather than staying on the current window where the button is situated. Is there a solution for this issue?
Code:
#Defining Export Button
def export(result):
with open ('students.csv', 'a', newline="") as f:
w = csv.writer(f, dialect='excel')
for record in result:
w.writerow(record)
messagebox.showinfo("Success!","Record Exported Successfully")
gate.mainloop()
Upvotes: 1
Views: 174
Reputation: 15098
Add a parent
argument to your messagebox
, like:
messagebox.showinfo("Success!","Record Exported Successfully",parent=gate)
This will direct it to show the message box with respect to that window. And gate.mainloop()
is not necessary as long as it's a Toplevel
. And if the window where your button is situated is not gate
then change the parent
argument to that windows name you want it to show message box on.
Upvotes: 3