0
私は選択された変数に基づいて関数を実行するTkinterオプションメニューを持っています。私が遭遇し続けるエラーがある:ここTkinter OptionsMenuの問題
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.3\lib\lib-tk\Tkinter.py", line 1486, in __call__
return self.func(*args)
File "C:\Python27\ArcGIS10.3\lib\lib-tk\Tkinter.py", line 3217, in __call__
self.__callback(self.__value, *args)
TypeError: unbound method func() must be called with RootGUI instance as first argument (got str instance instead)
コードです:
from Tkinter import *
import subprocess
import webbrowser
import threading
class RootGUI:
def __init__(self, master):
self.master = master
master.title("Greetings")
self.label = Label(master, text="Hello Mr. Swordy. What would you like to do?")
self.label.pack()
def func(self, value):
if "EC Network Manual" in value:
url = "https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/2014_NETWORK_MANUAL.pdf&action=default"
webbrowser.open_new(url)
elif "EC Field Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/2016_FIELD_MANUAL.pdf&action=default'
webbrowser.open_new(url)
elif "EC ODL Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/2016_ODL_MANUAL.pdf&action=default'
webbrowser.open_new(url)
elif "EC OH Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/2016_OH_MANUAL.pdf&action=default'
webbrowser.open_new(url)
elif "EC UG Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/2016_UG_MANUAL.pdf&action=default'
webbrowser.open_new(url)
elif "EC Blue Book" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Electric%20Manuals/Xcel-Energy-Standard-For-Electric-Installation-and-Use.pdf&action=default'
webbrowser.open_new(url)
elif "Gas Materials Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Gas%20Manuals/Gas%20Materials%20Manual%208-31-14.pdf&action=default'
webbrowser.open_new(url)
elif "Gas Design Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Gas%20Manuals/Gas%20Design%20Manual_V3.1.pdf&action=default'
webbrowser.open_new(url)
elif "Gas Compliance and Standards Manual" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Gas%20Manuals/Compliance%20and%20Stds%20Manual%20Nov%202016.pdf&action=default'
webbrowser.open_new(url)
elif "Gas Material Catalog" in value:
url = 'https://eneprojects.enengineering.com/XCEL/_layouts/15/WopiFrame.aspx?sourcedoc=/XCEL/Shared%20Documents/Xcel%20Distribution%20Design%20Project/Xcel%20Design%20Standards/Gas%20Manuals/GasMaterialCatalog-%20with%20drilldown.xlsm&action=default'
webbrowser.open_new(url)
root = Tk()
options = ["EC Network Manual", "EC Field Manual", "EC ODL Manual","EC OH Manual",
"EC UG Manual", "EC Blue Book", "Gas Materials Manual", "Gas Design Manual",
"Gas Compliance and Standards Manual","Gas Material Catalog"]
var = StringVar()
var.set("Documents")
drop = OptionMenu(root, var, *options, command=RootGUI.func)
drop.place(x=10, y=10)
my_gui = RootGUI(root)
root.mainloop()
それは私が、私はそれを行うだろうか、引数としてRootGUIを渡す必要があると述べ?アドバイスをいただければ幸いです。
注:これはスタイル標準に準拠していない可能性があることを認識しています。私はPythonに慣れていないコードが謝っています。