1
我想用Python2.7添加一些像Radiobutton這樣的小部件,但是我的代碼不能編譯。我想要的主要是當我點擊IN或OUT時顯示radio.on_clicked(sel)
的結果。這是我的代碼:如何用Python讀取Radiobutton的結果
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()
但是,當我點擊我單選框沒有看到在控制檯中。而且我還想讓班級索引來做到這一點。
非常感謝您的幫助!