2017-01-24 67 views
-3

我一直試圖與Tkinter一起創建一個GUI來選擇程序/網站 在啓動時啓動。Tkinter語法問題

web瀏覽器和subprocess.exe首戰在其他腳本中工作正常,併爲Tkinter的腳本模板的工作,但是當我開始增加更多的變數 它規定無效的語法(特別是在CoWeb變量,在DEF)

任何人都可以幫助我嗎?我缺少一些基本的東西嗎?

from Tkinter import Tk, Label, Button 
import subprocess 
import webbrowser 

class MyFirstGUI: 
    def __init__(self, master): 
     self.master = master 
     master.title("Greetings") 

     self.label = Label(master, text="Good Morning Mr. Swordy. What would you like to do?") 
     self.label.pack() 

     self.CoWeb_button = Button(master, text="ENE Website", command=self.CoWeb) 
     self.CoWeb_button.pack() 

     self.ProjWeb_button = Button(master, text="ENE Projects", command=self.ProjWeb) 
     self.ProjWeb_button.pack() 

     self.Excel_button = Button(master, text="Excel", command=self.Excel) 
     self.Excel_button.pack() 

     self.AutoCAD_button = Button(master, text="AutoCAD", command=self.AutoCAD) 
     self.AutoCAD_button.pack() 

     self.GEarth_button = Button(master, text="Google Earth", command=self.GEarth) 
     self.GEarth_button.pack() 

     self.close_button = Button(master, text="Close", command=master.quit) 
     self.close_button.pack() 



def Excel(self): 
     subprocess.Popen([r"C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE"] 

    def CoWeb(self): 
     url = "https://intranet.enengineering.com/SitePages/Home.aspx" 
     webbrowser.open_new(url) 

    def ProjWeb(self): 
     url = "https://eneprojects.enengineering.com/SitePages/Home.aspx" 
     webbrowser.open_new(url) 

    def AutoCAD(self): 
     subprocess.Popen([r"C:\Program Files\Autodesk\AutoCAD 2016\acad.exe"] 

    def GEarth(self): 
     subprocess.Popen([r""C:\Program Files (x86)\Google\Google Earth Pro\client\googleearth.exe"] 


root = Tk() 
my_gui = MyFirstGUI(root) 
root.mainloop() 
+1

你忘了所有的'subprocess.Popen([..]' –

+0

總是右括號。

的定義提出問題FULL錯誤信息(Traceback) – furas

回答

0

這沒有有效的Python語法:

def GEarth(self): 
     subprocess.Popen([r""C:\Program Files (x86)\Google\Google Earth Pro\client\googleearth.exe"] 

注意雙",即""。 只是刪除一個"

def GEarth(self): 
     subprocess.Popen([r"C:\Program Files (x86)\Google\Google Earth Pro\client\googleearth.exe"] 

此外,您縮進似乎是錯誤的。

def Excel(self): 
... 
def CoWeb(self): 

必須在同一水平:

def __init__(self, master): 
+0

謝謝!不幸的是它仍然返回錯誤,它指出:「Traceback(最近調用最後一個): 文件」C:/Python27/ArcGIS10.3/Scripts/TkinterGui「,行51,在 my_gui = MyFirstGUI(root) 文件「C:/Python27/ArcGIS10.3/Scripts/TkinterGui」,第30行,在__init__中 self.CoWeb_button = Button(master,text =「ENE Website」,command = self.CoWeb ) AttributeError:MyFirstGUI實例沒有屬性'CoWeb'「 – JSwordy

0

看起來你錯過了這句話閉幕括號:

def Excel(self): 
    subprocess.Popen([r"C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE"] 

閉幕括號也缺少AutoCAD和GEarth方法。