如何使用Python读取Radiobutton的结果

如何使用Python读取Radiobutton的结果,python,python-2.7,python-3.x,numpy,matplotlib,Python,Python 2.7,Python 3.x,Numpy,Matplotlib,我想在Python2.7中添加一些小部件,比如Radiobutton,但我的代码没有编译。我想要的主要是当我点击输入或输出时,显示收音机的结果。点击(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

我想在Python2.7中添加一些小部件,比如Radiobutton,但我的代码没有编译。我想要的主要是当我点击输入或输出时,显示
收音机的结果。点击(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()
但当我点击单选按钮时,我在控制台上什么也看不到。我还想保留类索引来实现这一点


非常感谢你的帮助

打印收音机。点击(sel)一点意义都没有。
radio。单击(sel)
在matplotlib回调注册表中注册回调,并在注册表中返回此回调的编号。因此,第一次调用它时,它可能会返回1,第二次返回2,等等。您越频繁地调用,回调注册表中的相同回调就越多,而其中一个就足够了

可能是以下内容正在做您需要的事情

import pylab as plt
from matplotlib.widgets import Button
from matplotlib.widgets import RadioButtons

def sel(var):
    if var == "IN":
        print "IN"
        return True
    elif var == "OUT":
        print "OUT"
        return False

def pre(event):
    print "You clicked the button"

axplot = plt.axes([0.11,0.92,0.08,0.07])
bplot = Button(axplot, 'Plot')
bplot.on_clicked(pre)

choice = plt.axes([0.44,0.92,0.08,0.07])
radio = RadioButtons(choice, ('IN', 'OUT'))
radio.on_clicked(sel)

plt.show()

点击(sel)打印收音机的线路毫无意义。
radio。单击(sel)
在matplotlib回调注册表中注册回调,并在注册表中返回此回调的编号。因此,第一次调用它时,它可能会返回1,第二次返回2,等等。您越频繁地调用,回调注册表中的相同回调就越多,而其中一个就足够了

可能是以下内容正在做您需要的事情

import pylab as plt
from matplotlib.widgets import Button
from matplotlib.widgets import RadioButtons

def sel(var):
    if var == "IN":
        print "IN"
        return True
    elif var == "OUT":
        print "OUT"
        return False

def pre(event):
    print "You clicked the button"

axplot = plt.axes([0.11,0.92,0.08,0.07])
bplot = Button(axplot, 'Plot')
bplot.on_clicked(pre)

choice = plt.axes([0.44,0.92,0.08,0.07])
radio = RadioButtons(choice, ('IN', 'OUT'))
radio.on_clicked(sel)

plt.show()