Reputation: 2096
I am trying to open a web page using PyQt5
after a button press in tkinter
window.
As soon as the new window opens, it resizes (downsizes in this case) the tkinter
window permanently.
Minimal code required to reproduce this
import sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
from tkinter import *
from threading import Thread
class Web:
def __init__(self,url,title='',size=False):
self.title=title
self.url=url
self.size=size
self.app=QApplication(sys.argv)
self.web=QWebEngineView()
self.web.setWindowTitle(self.title)
self.web.load(QUrl(self.url))
if size:
self.web.resize(self.size[0],self.size[1])
def open(self):
self.web.show()
sys.exit(self.app.exec_())
def launch():
web=Web('https://www.example.com')
web.open()
root=Tk()
button=Button(root,text='open',command=lambda:Thread(target=launch).start())
button.pack(padx=100,pady=100)
root.mainloop()
Images for reference
Both the images have the same height.
I would like to know the reason and a way to prevent this.
Upvotes: 1
Views: 183
Reputation: 2096
I have figured it out myself. PyQt
changes the dpi awareness which does not happen by default with tkinter
. Due to which the tkinter
window resized itself as soon as PyQt
was launched in the same main loop.
Since I am on a windows machine, using this solved the problem.
ctypes.windll.shcore.SetProcessDpiAwareness(1)
Upvotes: 1