Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用Tkinter的Python GUI,错误_Python 3.x_User Interface_Tkinter - Fatal编程技术网

Python 3.x 使用Tkinter的Python GUI,错误

Python 3.x 使用Tkinter的Python GUI,错误,python-3.x,user-interface,tkinter,Python 3.x,User Interface,Tkinter,我正在尝试制作一个带有两个按钮的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(

我正在尝试制作一个带有两个按钮的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()"""
将熊猫作为pd导入
将matplotlib.pyplot作为plt导入
将tkinter作为t导入
def onpick3(事件):
ind=event.ind
打印(“ID:,ind[0]+4,”,名称:,方法[ind[0]+2],”,值-x:,x[ind[0]+2])
def plotpareto():
图=plt.图()
ax1=图add_子批次(111)
ax1.散布(x[2:],y[2:],选取器=True)
对于索引中的i:
ax1.散射(x[i],y[i],c=“r”)
图canvas.mpl\u connect(“pick\u事件”,onpick3)
plt.show()
def compute():
first=输入(“输入最高优先级:”)
秒=输入(“输入下一个最高优先级:”)
imp=输入(“输入实现:”)
如果first==“GC”:
如果imp==“P02”:
col1='P02.1'
如果imp==“P01”:
col1=='P01.1'
如果imp=='Wille':
col1='Wille.1'
如果imp==“ISM”:
col1='ISM.1'
如果第二个==“GC”:
如果imp==“P02”:
col2='P02.1'
如果imp==“P01”:
col2=='P01.1'
如果imp=='Wille':
col2='Wille.1'
如果imp==“ISM”:
col2='ISM.1'
如果第一个==“QC”:
如果imp==“P02”:
col1='P02.2'
如果imp==“P01”:
col1=='P01.2'
如果imp=='Wille':
col1='Wille.2'
如果imp==“ISM”:
col1='ISM.2'
如果第二个==“QC”:
如果imp==“P02”:
col2='P02.2'
如果imp==“P01”:
col2=='P01.2'
如果imp=='Wille':
col2='Wille.2'
如果imp==“ISM”:
col2='ISM.2'
xl=pd.read\u excel(“Treecover1.xlsx”,na\u值='1000')
全球x
全局y
x=列表(xl[col1])
y=列表(xl[col2])
全局方法
方法=列表(xl['Methods'])
minx=9999
温度=[]
i=2
而i
错误: 2017-02-25 22:05:41.256 Python[85189:5428235]-[NSApplication _setup:]:发送到实例0x1053ca2a0的选择器无法识别 2017-02-25 22:05:41.257 Python[85189:5428235]引发了未捕获的异常 2017-02-25 22:05:41.257 Python[85189:5428235]-[NSApplication _setup:]:发送到实例0x1053ca2a0的选择器无法识别


请帮助。

此代码适用于我;但是,按钮未链接到此代码的函数,因此按下时它们不会执行任何操作。无论如何,以下GUI显示时不会出现错误:

当python代码在一台机器上而不是在另一台机器上工作时,我的第一个想法是,当我执行程序(即在本例中是2.X而不是3.X)或我的一个外部模块(即pandas、matplotlib或tkinter)损坏或在可疑机器上运行时,python的意外版本正在运行

了解以下情况将是有益的:

  • 这段当前代码(完全一样)是否为您抛出了错误
  • 如果是,这是完整的错误输出吗?通常,python会将错误追溯到特定的行,这显然非常有用
  • 如果可能的话,您是否可以使用虚拟数据而不是电子表格来复制此问题?除了您之外,任何人都很难在没有使用电子表格的情况下正确测试此代码。只是一个想法

  • 这个代码对我有用;但是,按钮未链接到此代码的函数,因此按下时它们不会执行任何操作。无论如何,以下GUI显示时不会出现错误:

    当python代码在一台机器上而不是在另一台机器上工作时,我的第一个想法是,当我执行程序(即在本例中是2.X而不是3.X)或我的一个外部模块(即pandas、matplotlib或tkinter)损坏或在可疑机器上运行时,python的意外版本正在运行

    了解以下情况将是有益的:

  • 这段当前代码(完全一样)是否为您抛出了错误
  • 如果是,这是完整的错误输出吗?通常,python会将错误追溯到特定的行,这显然非常有用
  • 如果可能的话,您是否可以使用虚拟数据而不是电子表格来复制此问题?除了您之外,任何人都很难在没有使用电子表格的情况下正确测试此代码。只是一个想法

  • 你知道如何在Mac上重新安装python吗?我自己不是Mac迷,所以我不太愿意在这里提供任何建议。文章可能有用。我确实倾向于说,在这种情况下重新安装python似乎有点过头了,但我也不能声称知道是什么导致了这一点上的错误。一个快速的网络搜索揭示了在经历这个错误的人中的一些共同点:Mac、Matplotlib和Tkinter。在这一点上,我觉得更像是一个模块问题。>>>>从appJar导入gui>>>app=gui()回溯(最近一次调用):文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/appJar/appJar.py”中的第1行文件“”,在init self.exe文件=os.path.basename(主文件)中的第410行AttributeError:模块“main”没有属性“file”。这本身就有一个错误。我不确定此时您指的是什么。请打开一个新的问题。你知道如何在Mac上重新安装python吗?我自己不是Mac的人,所以我不太愿意在这里提供任何建议。文章可能有用。我确实觉得有点喜欢吃巧克力