在运行tkinter应用程序时出现cefpython错误,这让我在没有Ctrl + C中断的情况下退出该错误

问题描述

这是我第一次尝试使用tkinter构建应用程序。它具有嵌入式cef浏览器窗口。这是代码(我知道这不是最好的代码):

import tkinter as tk
import sys,threading,os
from decimal import Decimal
from cefpython3 import cefpython as cef
from math import radians,sin,cos,acos
from tkinter import W,BOTH,TOP,LEFT,N,S,E,ttk

path = os.path.join(os.path.dirname("C:\\Users\\tanis\\Desktop\\Project\\PMS Calculator\\"))
logo_path = os.path.join(path,"logo.png")

def calculate(cood1,cood2):
    [lat1,long1] = cood1.split(',')
    [lat2,long2] = cood2.split(',')
    lat1 = radians(float(lat1))
    long1 = radians(float(long1))
    lat2 = radians(float(lat2))
    long2 = radians(float(long2))

    distance = 6371.01 * acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(long1 - long2))
    distance = round(distance,2)
    distance = distance * 1000
    print(f'The distance between these two points is {distance}m.')

def cef_thread(mapFrame):
    sys.excepthook = cef.ExceptHook
    window_info = cef.WindowInfo(mapFrame.winfo_id())
    window_info.SetAsChild(mapFrame.winfo_id(),rect)
    cef.Initialize()
    cef.CreateBrowserSync(window_info,url='https://developers.google.com/maps/documentation/utils/geocoder/embed')
    cef.MessageLoop()

def on_closing():
    print('Closing the program.')
    appRoot.destroy()
    cef.Shutdown()

#root level frame
appRoot = tk.Tk()
appRoot.title('PMS Calculator')
appRoot.geometry(str(int((appRoot.winfo_screenwidth())/1.3))+'x'+str(int((appRoot.winfo_screenheight())/1.3)))
appRoot.protocol('WM_DELETE_WINDOW',on_closing)
appRoot.rowconfigure(0,weight=1)
appRoot.columnconfigure(0,weight=1)
appRoot.update()

#setup logo
if os.path.exists(logo_path):
    logo = tk.PhotoImage(file=logo_path)
    appRoot.call("wm","iconphoto",appRoot._w,logo)

#Container Frame
container = ttk.Frame(appRoot,height=appRoot.winfo_height(),width=appRoot.winfo_width())
container.grid(row=0,column=0,sticky=(N,W))
container.rowconfigure(0,weight=1)
container.columnconfigure(0,weight=1)
container.update()
cheight = container.winfo_height()
cwidth = container.winfo_width()

#map wrapper frame
frameOne = ttk.Frame(container,height=int(cheight*0.7),width=cwidth)
frameOne.grid(row=0,W))
frameOne.rowconfigure(0,weight=1)
frameOne.columnconfigure(0,weight=1)
frameOne.update()
#calc wrapper frame
frameTwo = ttk.Frame(container,height=int(cheight-cheight*0.7),width=container.winfo_width())
frameTwo.grid(row=1,sticky=(S,W))
frameTwo.rowconfigure(0,weight=1)
frameTwo.columnconfigure(0,weight=1)
frameTwo.update()

#map labelframe
labelFrame1 = ttk.LabelFrame(frameOne,text='Fetch Coordinates',height=frameOne.winfo_height(),width=frameOne.winfo_width())
labelFrame1.grid(row=0,ipadx=2,ipady=2)
labelFrame1.rowconfigure(0,weight=1)
labelFrame1.columnconfigure(0,weight=1)
labelFrame1.update()
#calc labelframe
labelFrame2 = ttk.LabelFrame(frameTwo,text='Calculate',height=frameTwo.winfo_height(),width=frameTwo.winfo_width())
labelFrame2.grid(row=0,ipadx=5,ipady=5)
labelFrame2.rowconfigure(0,weight=1)
labelFrame2.columnconfigure(0,weight=1)
labelFrame2.update()

#Map labelFrame content
mapFrame = ttk.Frame(labelFrame1,height=labelFrame1.winfo_height(),width=labelFrame1.winfo_width())
mapFrame.grid(row=0,column=0)
mapFrame.rowconfigure(0,weight=1)
mapFrame.columnconfigure(0,weight=1)
mapFrame.update()
mwidth = mapFrame.winfo_width()
mheight = mapFrame.winfo_height()

# cood1 = tk.StringVar()
# cood2 = tk.StringVar()

#Calc labelFrame content
latlong1Label = ttk.Label(labelFrame2,text='Start Coordinates:')
latlong1Label.place(x=5,y=10)
latlong1Entry = ttk.Entry(labelFrame2)
latlong1Entry.place(x=6,y=35)
latlong2Label = ttk.Label(labelFrame2,text='End Coordinates:')
latlong2Label.place(x=5,y=75)
latlong2Entry = ttk.Entry(labelFrame2)
latlong2Entry.place(x=6,y=100)
calcButton = ttk.Button(labelFrame2,text='Check',command=calculate)
calcButton.place(x=5,y=125)

rect = [0,mwidth,mheight]
thread = threading.Thread(target=cef_thread,args=(mapFrame,))
thread.start()
appRoot.mainloop()

三件事,即:

  1. 运行该程序时,出现错误消息: [0818/141358.573:ERROR:quota_settings.cc(109)] Unable to compute QuotaSettings.我查了一下,发现它与GPU缓存有关,但无法将其包裹住以进行修复。
  2. 当我单击Entry(输入)字段时,它不会立即成为焦点,我必须最小化然后最大化应用程序以实现此目的。我是否需要使用类似latlong1Entry.set_focus()的东西?
  3. 尽管我将rowconfigurecolumnconfigure与应用程序框架配合使用,但它们并未调整大小。我知道一开始我已经设置了根窗口的大小,但是我不明白为什么它没有调整大小。

任何帮助将不胜感激(即使它稍微清除了代码)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...