【发布时间】:2017-03-15 16:30:00
【问题描述】:
我想在 Python2.7 中添加一些小部件,例如 Radiobutton,但我的代码无法编译。我想要的主要是当我点击IN或OUT时显示radio.on_clicked(sel)的结果。这是我的代码:
import pylab as plt
import numpy as np
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
from matplotlib.widgets import Button
from matplotlib.widgets import RadioButtons
import os
import Tkinter as tk
from tkFileDialog import askopenfilename
from tkFileDialog import asksaveasfile
import ntpath
from Tkinter import Label
from Tkinter import Listbox
from Tkinter import END
import Tix
import scipy
class Index(object):
ind = 0
def pre(self, event):
print radio.on_clicked(sel)
callback = Index()
axplot = plt.axes([0.11,0.92,0.08,0.07])
bplot = Button(axplot, 'Plot')
bplot.on_clicked(callback.pre)
choice = plt.axes([0.44,0.92,0.08,0.07])
radio = RadioButtons(choice, ('IN', 'OUT'))
def sel(var):
if var == "IN":
print "IN"
return True
elif var == "OUT":
print "OUT"
return False
plt.show()
但是当我单击单选按钮时,我在控制台中什么也看不到。而且我想保留类索引来做到这一点。
非常感谢您的帮助!
【问题讨论】:
标签: python python-2.7 python-3.x numpy matplotlib