0
QtGui의 대화를 사용하여 사용자의 입력을 얻으려고합니다. QFileDialog의 경우 예상대로 작동하지만 QInputDialog를 사용하면 대화 상자가 팝업되고 사용자 입력을 기다리지 않고 코드 실행을 계속합니다.QInputDialog를 모달로 설정하는 방법
from PyQt4 import QtGui
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from numpy import pi
class Canvas(FigureCanvas):
def __init__(self):
self.fig = Figure()
FigureCanvas.__init__(self, self.fig)
self.fig.canvas.mpl_connect('key_press_event',self.key_pressed)
self.fig.canvas.mpl_connect('button_press_event',self.on_left_click)
self.ax = self.fig.add_axes([0,0,1,1])
self.figure.canvas.show()
def key_pressed(self, event):
if event.key == 'f':
fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
'c:\\',"Image files (*.png *.jpg *.gif)")
print fname
def on_left_click(self,event):
# If the mouse pointer is not on the canvas, ignore buttons
if not event.inaxes: return
if event.button==1:
x=event.xdata
y=event.ydata
r, ok = QtGui.QInputDialog.getDouble(self, 'Text Input Dialog', 'Enter radius:', 10)
if ok:
self.ax.scatter(x, y, s=pi*r**2,c=0.5)
self.draw()
cnv = Canvas()
이제 작동합니다. 감사합니다. (Spyder 내에서 열었습니다. Spyder는 열어 두었습니다.) – Tomas