Python Forum
[PyQt] command require close window - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] command require close window (/thread-38738.html)

Pages: 1 2


command require close window - Krissstian - Nov-18-2022

Hi,
I have defined a command for a button wich terminates like this:

 # save map data to data object
                    data = io.BytesIO()
                    m.save(data, close_file=False)

                    webView = QWebEngineView()
                    webView.setHtml(data.getvalue().decode())
                    layout.addWidget(webView)

            if __name__ == '__main__':
                app = QApplication(sys.argv)
                app.setStyleSheet('''
                    QWidget {
                        font-size: 35px;
                    }
                ''')

                myApp = MyApp()
                myApp.show()


                try:
                    sys.exit(app.exec_())
                except SystemExit:
                    print('Closing Window...')
The problem is that when finnish to execute the command it also require to close the main window. where's the mistake, thanks.


RE: command require close window - deanhystad - Nov-18-2022

In a post about a button command that closes a window I would expect to see code that creates a button and binds it to a command that closes the window.


RE: command require close window - Krissstian - Nov-18-2022

(Nov-18-2022, 06:56 PM)deanhystad Wrote: In a post about a button command that closes a window I would expect to see code that creates a button and binds it to a command that closes the window.

Sorry, this is my button command:
show_map = Button(root, text='SHOW', font=("", 10), command=Map, width="10")
show_map.grid(row=0, column=5, padx=5, pady=0)
And this is def:
   class MyApp(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle('Map')
            self.window_width, self.window_height = 1366, 768
            self.setMinimumSize(self.window_width, self.window_height)
            layout = QVBoxLayout()
            self.setLayout(layout)
            coordinate = (latitude, longitude)

            m = folium.Map(
                tiles='Stamen Terrain',
                zoom_start=6,
                location=coordinate
            )
            folium.Marker(location=[latitude, longitude]).add_to(m)

            # save map data to data object
            data = io.BytesIO()
            m.save(data, close_file=False)

            webView = QWebEngineView()
            webView.setHtml(data.getvalue().decode())
            layout.addWidget(webView)

    if __name__ == '__main__':
        app = QApplication(sys.argv)
        app.setStyleSheet('''
            QWidget {
                font-size: 35px;
            }
        ''')

        myApp = MyApp()
        myApp.show()

    try:
        sys.exit(app.exec_())
    except SystemExit:
        print('Closing Window...')
Problem is after i press the button and plot the result on map, the command it not stop execute...


RE: command require close window - deanhystad - Nov-18-2022

Why would it stop executing? app.exec_() is going to run until all the windows are closed.


RE: command require close window - Krissstian - Nov-18-2022

(Nov-18-2022, 07:47 PM)deanhystad Wrote: Why would it stop executing? app.exec_() is going to run until all the windows are closed.

So, can you tell me haw can i solve the issue, i'm new in python. Thanks


RE: command require close window - deanhystad - Nov-18-2022

There is nothing to fix. It is working exactly as it is supposed to work.

It sounds like this is the wrong tool for the job. What are you trying to accomplish?


RE: command require close window - Krissstian - Nov-18-2022

(Nov-18-2022, 08:48 PM)deanhystad Wrote: There is nothing to fix. It is working exactly as it is supposed to work.

It sounds like this is the wrong tool for the job. What are you trying to accomplish?

I want after I close that window with the map to open it again through the same command but with new data plot. But now I can't do it because it close also the main window.


RE: command require close window - Axel_Erfurt - Nov-18-2022

use

         self.webView = QWebEngineView()
         self.webView.setHtml(data.getvalue().decode())
         layout.addWidget(self.webView)
Then use

self.webView.setHtml(data.getvalue().decode())
to load the new data without closing the window.


RE: command require close window - deanhystad - Nov-18-2022

What is preventing you from opening the window with new data?

Normally a GUI stays open. You push a button and it draws a plot. Maybe you enter some information, a filename or some numbers, you push the button and the old plot is replaced with a new plot.

It sounds like you have a script. It runs a program to display a plot. When you are done looking at the plot you close the window and the script creates another window that displays a plot. Is that correct?


RE: command require close window - Yoriz - Nov-18-2022

The Button code looks like tkinter it shows Map as being the code called on a button press,
but the definition of Map is not shown in any of the code.

The rest of the code shown is PyQt you should not mix a tkinter Button with PyQt.

Can you please show more complete code including the imports.