【问题标题】:GUI with Python using Tkinter, errors使用 Tkinter 的 Python 图形用户界面,错误
【发布时间】:2017-07-16 11:20:18
【问题描述】:

我正在尝试制作一个带有 2 个按钮的 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-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

请帮忙。

【问题讨论】:

  • >>> from appJar import gui >>> app = gui() Traceback(最近一次调用最后):文件“”,第 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'

标签: python-3.x user-interface tkinter


【解决方案1】:

此代码对我有用;但是,这些按钮没有链接到此代码的功能,因此按下时它们什么也不做。无论如何,以下 GUI 显示没有错误:

当 python 代码在一台机器上而不是另一台机器上运行时,我的第一个想法是,当我执行程序(即在这种情况下是 2.X 而不是 3.X)或我的一个外部模块时,正在运行意外版本的 python (即 pandas、matplotlib 或 tkinter)在可疑机器上已损坏或以其他方式操作不当。

了解以下内容会很有用:

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

【讨论】:

  • 你知道如何在Mac上重新安装python吗?
  • 我自己不是 Mac 用户,所以我很犹豫在这里提供任何建议。 This 文章可能有用。我确实倾向于说在这种情况下重新安装 python 似乎有点矫枉过正,但我​​现在也不能声称知道是什么导致了错误。快速的网络搜索揭示了遇到此错误的人之间的一些共性:Mac、Matplotlib 和 Tkinter。在这一点上对我来说似乎更像是一个模块问题。
  • >>> from appJar import gui >>> app = gui() Traceback(最近一次调用最后):文件“”,第 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: module 'main' has no attribute 'file' 这本身就会出错
  • 目前我不确定您指的是什么。请提出一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多