我正在使用python2.7.12,我想知道如何将* .chm文件添加到python脚本中,以便在按下F12
按钮时正确启动它?
以下是我到目前为止的情况:
def hchma():
webbrowser.open_new(r"file://C:\WINDOWS\ULIX TxT Editor\Resources\helpCenter\helpCentre11.chm")
def hchm(event):
webbrowser.open_new(r"file://C:\WINDOWS\ULIX TxT Editor\Resources\helpCenter\helpCentre11.chm")
但是当我在Win10以外的任何Windows操作系统上运行此代码时,它将打开web_browser而不是文件本身。这段代码适用于Windows 10。 这是我的根绑定标记
root.bind('<F12>', hchm)
答案 0 :(得分:1)
您可以使用子流程,直接打开
class GUIPopulator(Frame):
def __init__(self, parent):
Frame.__init__(self)
self.parent = parent
self.configure(bg='PeachPuff2')
self.columnconfigure(20, weight=1)
self.rowconfigure(30, weight=1)
self.curtab = None
self.image_window = None
self.img_path = os.getcwd() + '/Rotating_earth_(large).gif'
self.tabs = {}
self.pack(fill=BOTH, expand=1, padx=5, pady=5)
self.parent.bind("<Configure>", self.move_me)
self.column = 0
self.row = 0
def move_me(self, event):
if self.image_window != None:
h = self.parent.winfo_height()
w = self.parent.winfo_width()
self.image_window.geometry('+{}+{}'.format(self.parent.winfo_x() + w - 250,
self.parent.winfo_y() + h - 250))
def on_enter(self, event):
if self.image_window == None:
self.image_window = Toplevel(self)
self.image_window.attributes("-topmost", True)
h = self.parent.winfo_height()
w = self.parent.winfo_width()
self.image_window.geometry('+{}+{}'.format(self.parent.winfo_x() + w - 250,
self.parent.winfo_y() + h - 250))
self.img = PhotoImage(file=self.img_path)
self.image_window.title("Preview")
self.canvas = Canvas(self.image_window, width=200, height=200)
self.canvas.pack()
self.canv_image = self.canvas.create_image(100, 100, image=self.img)
else:
self.img = PhotoImage(file= self.img_path)
self.canvas.itemconfig(self.canv_image, image = self.img)