我正在开发一个需要使用 pyppeer 来控制铬实例的程序。当我使用返回按钮时,我遇到了麻烦,窗口的大小被改变了。我该如何防止这种情况发生?
这是我的代码的缩短版本
import pyppeteer
import asyncio
import threading
import subprocess
import tkinter as tk
class ThreadedInstance():
def __init__(self, command):
self.ThreadingCommand = lambda: subprocess.run('{}'.format(command), shell = True)
self.Thread = threading.Thread(target = self.ThreadingCommand)
self.Thread.start()
def createInternet():
internet = ThreadedInstance('chromium-browser --start-fullscreeb --start-maximized --remote-debugging-port=9222 www.google.com')
global browser
global page
async def main():
browser = await pyppeteer.connect(browserURL='http://127.0.0.1:9222', autoclose=False)
asyncio.get_event_loop().run_until_complete(main())
class GUILocate():
def __init__(self):
self.root = tk.Tk()
self.root.overrideredirect(True)
self.root.geometry('100x100')
self.backwardsButton = tk.Button(self.root, text = 'Back')
self.backwardsButton.place(x=0, y=0, width = 100, height = 100)
self.backwardsButton.config(command = lambda: asyncio.get_event_loop().run_until_complete(self.goBack()))
self.root.mainloop()
async def goBack(self):
browser = await pyppeteer.connect(browserURL='http://127.0.0.1:9222', autoclose=False)
pages = await browser.pages()
currentPage = pages[0]
await currentPage.goBack()
if __name__ == '__main__':
createInternet()
locate = GUILocate()
[ 1