Hi everyone, my new from is in front of my main form but its not activate! I have to click on in to become activate.
How can I handle it ?
Is it possible to minimize the main form when new one opens?
here is my code to open new form from clicking a button in python
def carrepfrom():
car_report_form = Tk()
car_report_form.title("فرم گزارش گیری از ماشین آلات")
car_report_form.resizable(width=False, height=False)
car_report_form.geometry('500x500')
btn1 = Button(car_report_form, text='test')
btn1.place(x=10, y=10)
car_report_form.mainloop()
car_report_btn = Button(win, text='گزارش گیری از ماشین آلات', command=lambda: carrepfrom())
car_report_btn.place(x=560, y=130)
I changed my code to tkinter.Toplevel but steel the problem appears!!
the secend form is not activate and messegeboxes shown on my old form (main form)
What do you mean by this?
Quote:the secend form is not activate
Does the second window not appear? It must be that you are not calling the function that creates the toplevel window.
Quote:messegeboxes shown on my old form (main form)
What are "messegeboxes"? I think of a message box as a popup window that displays a message. It is a dialog style window that disappears when you press the Ok button. Do you mean adding widgets like Label, Text or Entry? These must be added to the new window just like the button. You must pass the window to parent the widget as an argument in the create call (i.e. tk.Label(new_window, text="This is text in the new window"). When you don't specify a window for a widget, the widget is added to the root window.
tk.Label(text="This will appear in the root window").pack()
tk.Label(popup, text="This will appear in the popup window").pack()
This code makes two windows with buttons displaying the other window:
import tkinter as tk
class PopupWindow(tk.Toplevel):
def __init__(self, parent, *args, **kwargs):
super().__init__(*args, **kwargs)
self.parent = parent
button = tk.Button(self, text="This is the popup window", command=self.button_callback)
button.pack(padx=50, pady=50)
def button_callback(self):
self.parent.deiconify()
self.withdraw()
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.popup_window = PopupWindow(self)
self.popup_window.withdraw()
button = tk.Button(self, text="This is the root window", command=self.button_callback)
button.pack(padx=50, pady=50)
def button_callback(self):
self.popup_window.deiconify()
self.withdraw()
MainWindow().mainloop()
You may have a good reason for making our interface work this way, but generally this is not a good way to design a user interface. Most user interfaces have only one main window that changes the view to perform different tasks. Any other windows are dialogs that appear for a short time to accomplish a specific task, like a file open dialog.
Thanks deanhystad for your time. I'm amatour in programming. I dont know about changing view , How can I do it?
I simply code this way in command of a button to show a new window and do some work like reporting , add, edit and etc for my database cars
here it is:
#its my main form
win=Tk()
# in this block the user will add information of his company cars
#
#new form for reporting
def report_form():
rep_form=tk.Toplevel()
rep_form.mainloop()
# a button to show a new form for get any report of cars
btn1=Button(win,text='report',command=report_form)
win.mainloop()
after clicking the btn1 , it will show the rep_form . problem is here , the first form (win) steel is active form and the user must click on the second form (rep_form) to add data and use it
How can I handle it?