[英]PyQt5 resizes tkinter window automatically
在tkinter
Z05B8C74CBD96FFB2DE4C1A35270 中按下按鈕后,我正在嘗試使用PyQt5
打開 web 頁面。
一旦新的 window 打開,它就會永久調整(在這種情況下縮小) tkinter
window 的大小。
重現此代碼所需的最少代碼
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()
圖片供參考
兩個圖像具有相同的高度。
我想知道原因和防止這種情況的方法。
我自己已經弄清楚了。 PyQt
更改默認情況下不會發生的 dpi 感知tkinter
。 因此,一旦PyQt
在同一主循環中啟動, tkinter
window 就會自行調整大小。
由於我在 windows 機器上,使用它解決了問題。
ctypes.windll.shcore.SetProcessDpiAwareness(1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.