- 论坛徽章:
- 0
|
本帖最后由 虔诚的墨鱼 于 2011-06-30 14:26 编辑
环境 windows7 + wingide + python2.6
脚本用pythonw命令运行正常,但是用wingide运行调试时就出现上图的情况。求高手解答。
点击SQL2008时出现这种情况,点击ACCESS可正常输出。
代码如下:
# -*- coding:utf-8 -*-
#file: wxPythonButtonEvent.py
#
import wx
class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(parent = None,title = 'wxPython',size = (300,170))
panel = wx.Panel(frame, -1)
self.button1 = wx.Button(panel, -1,'Access',pos=(50,50))
self.Bind(wx.EVT_BUTTON,
self.Access,
self.button1)
self.button2 = wx.Button(panel, -1 ,'SQL2008',pos=(150,50))
self.Bind(wx.EVT_BUTTON,
self.SQL2008,
self.button2)
self.button1.SetDefault()
frame.Show()
return True
def Access(self,event):
import odbc
con = odbc.odbc('podbc')
cursor = con.cursor()
cursor.execute('select id, name from people')
r = cursor.fetchall()
print r
con.commit()
cursor.close()
con.close()
def SQL2008(self,event):
import pymssql
conn = pymssql.connect(host='x.x.x.x',user='x',password='x',database='x')
cur = conn.cursor()
cur.execute('SELECT TOP 10 id, m_name FROM qingtiandy_movie' )
row = cur.fetchone()
while row:
print "ID=%d,Name=%s" %(row[0],row[1])
row = cur.fetchone()
conn.close()
app = MyApp()
app.MainLoop()
下面代码单独运行可正常输出,但是加入到按钮动作中就出错
import pymssql
conn = pymssql.connect(host='x.x.x.x',user='x',password='x',database='x')
cur = conn.cursor()
cur.execute('SELECT TOP 10 id, m_name FROM qingtiandy_movie' )
row = cur.fetchone()
while row:
print "ID=%d,Name=%s" %(row[0],row[1])
row = cur.fetchone()
conn.close() |
|