1
votes

I am trying to make a GUI with 2 buttons. But I keep running into the same error.

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()"""

Error: 2017-02-25 22:05:41.256 Python[85189:5428235] -[NSApplication _setup:]: unrecognized selector sent to instance 0x1053ca2a0 2017-02-25 22:05:41.257 Python[85189:5428235] An uncaught exception was raised 2017-02-25 22:05:41.257 Python[85189:5428235] -[NSApplication _setup:]: unrecognized selector sent to instance 0x1053ca2a0

Please help.

1
>>> from appJar import gui >>> app = gui() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/appJar/appjar.py", line 410, in init self.exe_file = os.path.basename(theMain.__file__) AttributeError: module 'main' has no attribute 'file' - Abhinav Goel

1 Answers

0
votes

This code works for me; however, the buttons aren't linked to this code's functions so they do nothing when pressed. Regardless, the following GUI displays with no errors:

enter image description here

My first thought when python code works on one machine and not another is that an unexpected version of python is running when I execute the program (i.e. 2.X instead of 3.X in this case) or one of my external modules (i.e. pandas, matplotlib, or tkinter) is corrupt or otherwise acting screwy on the suspect machine.

It would be useful to know the following:

  1. Is this current code (exactly as is) throwing an error for you?
  2. If so, is this the full error output? Normally, python traces an error back to a particular line, which would obviously be very helpful.
  3. If possible, could you see if this issue can be replicated using dummy data instead of the spreadsheet? It will be difficult for anyone but you to test this code properly without having the spreadsheet you are using. Just a thought.