Replies: 1 comment
-
The life cycle of an basic application using dearpygui being an infinite drawing loop for a system window, you cannot have two windows running properly in the same thread because you never exit the main draw loop as long as his window is open, this exemple should probably do what you want by splitins the program into 3 process (1host and 1 per window): import multiprocessing
import dearpygui.dearpygui as dpg
def create_first_window(close_second_event, close_first_event):
dpg.create_context()
with dpg.window(label="First Window", width=300, height=200):
dpg.add_text("This is the first window.")
dpg.add_button(label="Close This Window", callback=lambda: close_first_event.set())
dpg.add_button(label="Close Second Window", callback=lambda: close_second_event.set())
dpg.create_viewport(title='First Window', width=600, height=400)
dpg.setup_dearpygui()
dpg.show_viewport()
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
if close_first_event.is_set():
break
dpg.destroy_context()
def create_second_window(close_first_event, close_second_event):
dpg.create_context()
with dpg.window(label="Second Window", width=300, height=200):
dpg.add_text("This is the second window.")
dpg.add_button(label="Close This Window", callback=lambda: close_second_event.set())
dpg.add_button(label="Close First Window", callback=lambda: close_first_event.set())
dpg.create_viewport(title='Second Window', width=600, height=400)
dpg.setup_dearpygui()
dpg.show_viewport()
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
if close_second_event.is_set():
break
dpg.destroy_context()
if __name__ == '__main__':
close_first_event = multiprocessing.Event()
close_second_event = multiprocessing.Event()
process1 = multiprocessing.Process(target=create_first_window, args=(close_second_event, close_first_event))
process2 = multiprocessing.Process(target=create_second_window, args=(close_first_event, close_second_event))
process1.start()
process2.start()
process1.join()
process2.join() Or for 10 windows: import multiprocessing, time
import dearpygui.dearpygui as dpg
def close_all(wid, shared, event):
shared["imunity"] = wid
shared["action"] = "close_all"
event.set()
time.sleep(0.1)
event.clear()
def create_window(wid, job_board, shared, event):
dpg.create_context()
with dpg.window(label=f"Window {wid}", width=300, height=200):
dpg.add_button(label="Close This Window", callback=dpg.stop_dearpygui)
dpg.add_button(label="Close other Window", callback=lambda: job_board.put({"author": wid, "action": "close"}))
dpg.add_button(label="Close all other Window", callback=lambda: close_all(wid, shared, event))
dpg.add_button(label="Close all Window", callback=lambda: close_all(-1, shared, event))
dpg.create_viewport(title=f"Window {wid}", width=600, height=400)
dpg.setup_dearpygui()
dpg.show_viewport()
while dpg.is_dearpygui_running():
dpg.render_dearpygui_frame()
while not job_board.empty():
msg = job_board.get()
if msg["author"] == wid:
continue
if msg["action"] == "close":
return dpg.stop_dearpygui()
else:
print("receive message:", msg)
dpg.set_value("first_window_received_text", msg)
if event.is_set():
if shared["imunity"] != wid and shared["action"] == "close_all":
return dpg.stop_dearpygui()
dpg.stop_dearpygui()
job_board = multiprocessing.Queue()
process_qtt = 10
process_list = []
data_manager = multiprocessing.Manager()
shared = data_manager.dict()
event = multiprocessing.Event()
for i in range(0, process_qtt):
process_list.append(multiprocessing.Process(target=create_window, args=(i, job_board, shared, event)))
process_list[i].start()
for i in range(0, process_qtt):
process_list[i].join() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to create applictaion with two windows:
Window1 has a button to close window1. After closing window1, window2 appears, but window1 is not disappear at all. Is it possible? May create some independent windows?
?
Files and code:
main.py
window1.py:
window2.py
Beta Was this translation helpful? Give feedback.
All reactions