Python Forum
How can I run an interface I made using PyQt5 and a Map program I made using Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I run an interface I made using PyQt5 and a Map program I made using Tkinter
#1
I am making an interface for an Unmanned Aerial Vehicle. I have a main interface that shows the data I get from the dronekit and the attitude indicator. I made this main interface using PyQt5, first I was going to add a map directly to this interface I made with PyQt5, but the map I used could not functionally work on the interface I made over PyQt5. So I decided to separate the main interface and the map. I made the map using "tkintermapwiever". When I run the two separately, it works smoothly and stably. But since we have a single tool and we will connect through the same server, both programs need to run simultaneously, my research has not yielded any results. I have tried Threading and Processing methods, but they work sequentially, not at the same time. So for example, my main interface opens first, and after I close my interface, my map application opens. It shouldn't be like this, both should open side by side at the same time.I would be very grateful if you can help. Thank you..
Reply
#2
Show what you have tried
Reply
#3
(Nov-07-2023, 01:53 AM)deanhystad Wrote: Show what you have tried

And there's this extra problem: in the code snippet below, as soon as I import root.tk, the map opens automatically.

block of code where I call two different files and try multiprocessing:

from multiprocessing import Process
from mainMap import root_tk
from mainarayüz import main


def arayuz() :
    p1 = Process(target= main())
    p2 = Process(root_tk.mainloop())
    
    p1.start()
    p2.start()
    p1.join()
    p2.join()

if __name__ == '__main__' :
    arayuz()
`
Reply
#4
A couple problems. When you import a module the first time, Python executes the module code. If you don't want to draw the map you must put that code inside a function or hide it behind if __name__ == '__main__' :. The bigger problem is it sounds like you are running tk in one process and mainloop in another. That will not work. You must create your windows and run mainloop in the same process.
Reply
#5
(Nov-09-2023, 08:27 PM)deanhystad Wrote: A couple problems. When you import a module the first time, Python executes the module code. If you don't want to draw the map you must put that code inside a function or hide it behind if __name__ == '__main__' :. The bigger problem is it sounds like you are running tk in one process and mainloop in another. That will not work. You must create your windows and run mainloop in the same process.

from multiprocessing import Process

def ana() :
    from mainMap import root_tk
    from mainarayüz import main
    p1 = Process(target=(root_tk, main))
    p1.start()

ana()
like this?
Reply
#6
What benefit are you getting from running everything in a separate process?

You don't have to use mainloop(). Is there a way you could periodically call window.update() for the tk root window? I've never tried running Qt and Tk in the same process like this, but it is worth a try.

If this was me, I would drop either Qt or Tkinter and do everything using one GUI toolkit. Since it sounds like the map is the most complicated thing, I would say bye bye Qt py.
Reply
#7
(Nov-09-2023, 09:37 PM)deanhystad Wrote: What benefit are you getting from running everything in a separate process?

You don't have to use mainloop(). Is there a way you could periodically call window.update() for the tk root window? I've never tried running Qt and Tk in the same process like this, but it is worth a try.

If this was me, I would drop either Qt or Tkinter and do everything using one GUI toolkit. Since it sounds like the map is the most complicated thing, I would say bye bye Qt py.
You are right, but for now I need to solve this problem, because it is urgent. After that, I'll put the two together via Qt or Tkinter. At first I tried using the folium library in Qt5, but it was technically impossible to update the marker in folium, and I didn't want to develop the interface in Tkinter. So I came up with this solution, but I can't make it work. I just managed to run both apps together, but after 1 second both apps froze and didn't update themselves.
I will post the code:
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
from sarsgui_taslak import Ui_MainWindow
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QTimer
from geopy.geocoders import OpenCage
from PyQt5.QtGui import QFont,  QColor
from connecBaglanti import connect, connection_string, vehicle , VehicleMode, LocationLocal
from attitude_indicator import AttitudeIndicator
import datetime
import time
import math
import tkinter as tk
import tkintermapview
import time
import threading
import os
from PIL import Image, ImageTk
from connecBaglanti import connect, connection_string, vehicle, lat, lon
from multiprocessing import Process

# print("Simülatör başlatılıyor (SITL)")
# connection_string = "tcp:127.0.0.1:5762"

# print("Araç şurada bağlanıyor: %s" % (connection_string,))
# vehicle = connect(connection_string, wait_ready=False)
# # lat = vehicle.lsocation.global_relative_frame.lat
# lon = vehicle.location.global_relative_frame.lon

opencage_api_key = "52a.........................0"

class MainPage(QMainWindow):
    def __init__(self):
        super().__init__()
        
######MAIN INTERFACE STUFFFFFFFFFFFFFFFFFFFFFFFF

####################################MAP WITH TKINTER##############################################
def mapgui() :
    lat = vehicle.location.global_relative_frame.lat
    lon = vehicle.location.global_relative_frame.lon
    # create tkinter window
    root_tk = tk.Tk()
    root_tk.geometry(f"{1000}x{700}")
    root_tk.title("SarsGUI Map")
###MAP STUFFFF
    root_tk.mainloop()


    
def maingui():
    uygulama = QApplication([])
    pencere = MainPage()
    pencere.show()
    sys.exit(uygulama.exec_())




if __name__ == '__main__':
    pyqt_process = Process(target=maingui)
    tkinter_process = Process(target=mapgui)

    pyqt_process.start()
    tkinter_process.start()

    pyqt_process.join()
    tkinter_process.join()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Graphic Interface with Tkinter IgnacioMora23 0 1,798 May-27-2021, 04:35 AM
Last Post: IgnacioMora23
  [Tkinter] Noob question:Using pyttsx3 with tkinter causes program to stop and close, any ideas? Osman_P 4 5,339 Nov-14-2020, 10:51 AM
Last Post: Osman_P
  Made new instance - button still goes to old instance nanok66 6 3,002 Nov-06-2020, 07:44 PM
Last Post: deanhystad
  [Tkinter] Indentation for Tkinter-made Text Editor ShakeyPakey 4 5,181 Jun-08-2020, 03:13 PM
Last Post: menator01
Question [Tkinter] Defining a self made module's function to interact with the main .py variables? Gilush 9 4,372 Jun-08-2020, 09:08 AM
Last Post: Gilush
  PyQt5 How do you make a functioning login and registration program? YoshikageKira 4 7,200 Jan-17-2020, 09:51 PM
Last Post: pavulon
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 10,862 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  Exiting/killing a program with tkinter but leaving the graphic on the screen jpezz 3 3,992 Apr-07-2019, 02:13 PM
Last Post: jpezz
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,840 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  [Tkinter] Unable to Obtain values from one Tkinter Program into another nilaybnrj 1 2,581 Aug-24-2018, 01:24 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020