2017-02-25 13 views
1

私は2つのボタンでGUIを作ろうとしています。しかし、私は同じエラーに実行し続けます。Tkinterを使ったPythonのGUI、エラー

import pandas as pd 
import matplotlib.pyplot as plt 
import tkinter as t 

def onpick3(event): 
     ind = event.ind 
     print("ID:", ind[0]+4, ", Name:",method[ind[0]+2], ", Value-x:",x[ind[0]+2]) 

def plotpareto(): 
    fig = plt.figure() 
    ax1 = fig.add_subplot(111) 

    ax1.scatter(x[2:], y[2:], picker=True) 
    for i in index: 
     ax1.scatter(x[i], y[i], c = "r") 
    fig.canvas.mpl_connect('pick_event', onpick3) 
    plt.show() 

def compute(): 
    first = input("Enter Highest Priority: ") 
    second = input("Enter Next Highest Priority: ") 
    imp = input("Enter Implementation: ") 
    if first == 'GC': 
     if imp == 'P02': 
      col1 = 'P02.1' 
     if imp == 'P01': 
      col1 == 'P01.1' 
     if imp == 'Wille': 
      col1 = 'Wille.1' 
     if imp == 'ISM': 
      col1 = 'ISM.1' 
    if second == 'GC': 
     if imp == 'P02': 
      col2 = 'P02.1' 
     if imp == 'P01': 
      col2 == 'P01.1' 
     if imp == 'Wille': 
      col2 = 'Wille.1' 
     if imp == 'ISM': 
      col2 = 'ISM.1' 
    if first == 'QC': 
     if imp == 'P02': 
      col1 = 'P02.2' 
     if imp == 'P01': 
      col1 == 'P01.2' 
     if imp == 'Wille': 
      col1 = 'Wille.2' 
     if imp == 'ISM': 
      col1 = 'ISM.2' 
    if second == 'QC': 
     if imp == 'P02': 
      col2 = 'P02.2' 
     if imp == 'P01': 
      col2 == 'P01.2' 
     if imp == 'Wille': 
      col2 = 'Wille.2' 
     if imp == 'ISM': 
      col2 = 'ISM.2' 

    xl = pd.read_excel("Treecover1.xlsx", na_values = '1000') 
    global x 
    global y 

    x = list(xl[col1]) 
    y = list(xl[col2]) 
    global method 
    method = list(xl['Methods']) 

    minx = 9999 
    temp = [] 

    i = 2 
    while i < len(x): 
     if int(x[i]) < minx and int(x[i]) != 0: 
      temp.clear() 
      temp.append(i) 
      minx = x[i] 
     elif int(x[i]) == minx: 
      temp.append(i) 
     i+=1 

    miny = y[temp[0]] 

    index = [] 
    for j in temp: 
     if y[j] < miny and y[j] != 0: 
      miny = y[j] 
      index.clear() 
      index.append(j) 
     elif y[j] == miny: 
      index.append(j) 

"""window = t.Tk() 
btn = t.Button(window, text = 'Compute') 
btn1 = t.Button(window, text = 'Plot') 
btn.pack() 
btn1.pack()`enter code here` 
window.mainloop()""" 

エラー: 2017年2月25日22:05:41.256パイソン[85189:5428235] - [NSApplicationのの_setup:]:05:認識されないセレクター 2017年2月25日22インスタンス0x1053ca2a0に送信41.257 Pythonは[85189:5428235]キャッチされない例外が 2017年2月25日22育った:05:41.257 Pythonの[85189:5428235] - [NSApplicationのの_setupは:]:認識されていないセレクタが助けてくださいインスタンスに0x1053ca2a0

を送りました。

+0

>>> appJar輸入GUI >>>アプリは= GUI(から) トレースバック(最新の呼び出しの最後): ファイル「/ライブラリ/フレームワーク/ Pythonで ファイル ""、ライン1、 .framework/Versions/3.6/lib/python3.6/site-packages/appJar/appjar.py "、行410、__init__ self.exe_file = os.path.basename(theメイン.__ファイル_) AttributeError:module '__main__ 'には属性' __file__ 'がありません –

答えて

0

このコードは私にとっては役に立ちます。ただし、ボタンはこのコードの関数にリンクされていないため、押されても何もしません。エラーなしとにかかわらず、以下のGUIが表示されます。

enter image description here

私が最初に考えたのpythonコードは一台のマシン上で動作していない他は私がプログラムを実行する際のpythonの予期しないバージョンが実行されていることである(つまり、2。私の外部モジュール(例えば、pandas、matplotlib、またはtkinter)の1つが壊れているか、または疑わしいマシンでねじれて動作しています。

次の知っておくと便利でしょう:

  1. があなたのためにエラーを投げる(正確であるように)、この現在のコードですか?
  2. もしそうなら、これは完全なエラー出力ですか?通常、pythonは特定の行にエラーを戻しますが、これは明らかに非常に役立ちます。
  3. 可能であれば、スプレッドシートの代わりにダミーデータを使用してこの問題を複製できるかどうかを確認できますか?あなた以外の誰もあなたが使っているスプレッドシートを持っていなくても、このコードを適切にテストすることは難しいでしょう。ちょっとした考え。
+0

Macでpythonを再インストールする方法はありますか? –

+0

私は自分自身のMacの男ではないので、私はここで何か助言を提供することを躊躇しています。 [This](http://docs.python-guide.org/en/latest/starting/install/osx/)の記事が役に立つかもしれません。このような状況では、Pythonを再インストールするのは残酷かもしれないようですが、この時点で何が原因で発生しているのかを知ることはできません。クイックウェブ検索では、このエラーが発生した人々の間でMac、Matplotlib、およびTkinterの共通点が明らかになりました。この時点でモジュール問題のように思えます。 –

+0

>>> appJarインポートGUIから >>>アプリ= GUI() トレースバック(最後の最新の呼び出し): ファイル ""、 ファイルの行1、「/Library/Frameworks/Python.framework/Versions /3.6/lib/python3.6/site-packages/appJar/appjar.py "、行410、__init__ self.exe_file = os.path.basename(theMain。__FILE__) ははAttributeError:モジュールの__main__ 'は属性「__FILE__」 これは、私はあなたがこの時点で参照しているかわからないんだけど、それ自体 –

関連する問題