URN Logo
UNIX Resources » Linux » China Linux Forum » Python 编 程 » 5 » [精华] 请教高手!
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
[精华] 请教高手!
[精华] 请教高手! - icgre [2005-11-15 11:07 | 5,130 byte(s)]
 
[精华] Re: 请教高手! - icgre [2005-11-15 14:18 | 4,455 byte(s)]
 
Re: 请教高手! - limodou [2005-11-15 18:01 | 216 byte(s)]
 
Re: 请教高手! - icgre [2005-11-16 14:45 | 756 byte(s)]
 
Re: 请教高手! - limodou [2005-11-16 20:28 | 202 byte(s)]
 
Re: 请教高手! - passworld [2005-11-17 00:57 | 80 byte(s)]
 
Re: 请教高手! - icgre [2005-11-17 09:10 | 165 byte(s)]
 
Re: 请教高手! - limodou [2005-11-17 09:46 | 75 byte(s)]
 
[精华] Re: 请教高手! - limodou [2005-11-15 13:32 | 114 byte(s)]
 
Subject: [精华] 请教高手!
Author: icgre    Posted: 2005-11-15 11:07    Length: 5,130 byte(s)
[Original] [Print] [Top]
我写了一段代码!但是一进入界面,数据库连接就直接运行,
那位高手知道如何解决啊!让点击按钮后再运行怎么处理啊!

##################writed by icgre######################
import dbi, odbc
from Tkinter import *
import pymqi, CMQC, sys, os, string,sys
from init import initdata
from time import strftime,sleep
class panel(Frame):
def __init__(self,initlabel=""):
Frame.__init__(self)
self.pack(expand=YES,fill=BOTH)
self.master.title="Message pass managerV1.0"
self.master.geometry("800x300")
self.source=StringVar()
self.text1=Entry(self,name="text1",textvariable=self.source)
self.source.set("")
self.text1.bind("<Return>",self.action)
self.text1.pack()
self.labelvalue=StringVar()
self.label1=Label(self,textvariable=self.labelvalue)
self.labelvalue.set(initlabel)
self.label1.pack()
self.button1=Button(self,text="O k",command=self.queding)
self.button1.pack()
self.button2=Button(self,text="Cancel",command=self.quxiao)
self.button2.pack()
try:
odbcname=initdata().odbcname
user=initdata().user
password=initdata().password
except:
self.labelvalue.set("Error the init.py is not correct!")
try:
dbc = odbc.odbc(odbcname+"/"+user+"/"+password)
except:
self.labelvalue.set("Error the database link is not correct!")
sql="select convert(varchar,order_name),button_name,sql from change_table"
crsr = dbc.cursor()
crsr.execute(sql)
result = crsr.fetchall()
for i in result:
self.button3=Button(self,text=i[1])
self.button3.bind("<Enter>",self.link(i[0]))
self.button3.pack()
def link(self,order_id):
odbcname=initdata().odbcname
user=initdata().user
password=initdata().password
dbc = odbc.odbc(odbcname+"/"+user+"/"+password)
sql="select * from change_table where order_name="+order_id
crsr = dbc.cursor()
crsr.execute(sql)
result = crsr.fetchall()
sql1=result[0][2]
crsr = dbc.cursor()
crsr.execute(sql1)
result1 = crsr.fetchall()
for i in result1:
str=""
for s in range(len(crsr.description)):
str=str+i[s]+"@"

self.putmessage(initdata().channel,initdata().host,initdata().port,initdata().quemgr,i
nitdata().queue,str)
def putmessage(self,channel,host,port,quemgr,queue,message):
arg_array_size=len(message)
host=host.upper()
quemgr=quemgr.upper()
queue=queue.upper()
command=channel+"/TCP/"+host+"("+port+")"
os.environ['MQSERVER'] =command
os.environ['CCSID'] ="1381"
qmgr = pymqi.QueueManager()
putQ= pymqi.Queue(qmgr,queue)
counter=0
while counter < arg_array_size:
putQ.put(message[counter])
print "Sent Message :",message[counter]
counter = counter +1
def action(self,event):
print "212112"
def queding(self):
source=self.source.get()
if len(source)<>0:

self.putmessage(initdata().channel,initdata().host,initdata().port,initdata().quemgr,i
nitdata().queue,source)
labelvalue="putmessage '"+source+"' successfully! time
is:"+strftime("%Y%m%d%H%M%S")+" "
self.labelvalue.set(labelvalue)
string1="j"
filepath=sys.prefix+string1[0]+"putmessage.log"
file=open(filepath,'a')
file.write("putmessage '"+source+"' successfully! time
is:"+strftime("%Y%m%d%H%M%S")+" ")
file.close()
else:
labelvalue="please input the message! time is:"+strftime("%Y%m%d%H%M%S")+" "
self.labelvalue.set(labelvalue)
string1="j"
filepath=sys.prefix+string1[0]+"putmessage.log"
file=open(filepath,'a')
file.write("Error! The Message Is Null! time is:"+strftime("%Y%m%d%H%M%S")+" ")
file.close()
def quxiao(self):
self.source.set('')
if __name__=="__main__":
panel().mainloop()
[Original] [Print] [Top]
Subject: [精华] Re: 请教高手!
Author: limodou    Posted: 2005-11-15 13:32    Length: 114 byte(s)
[Original] [Print] [Top]
因为你没有把数据库操作的代码放在一个事件处理中,而是放在了panel的初始化函数中,自然panel一初始化就一直运行下去了。
----
[Original] [Print] [Top]
Subject: [精华] Re: 请教高手!
Author: icgre    Posted: 2005-11-15 14:18    Length: 4,455 byte(s)
[Original] [Print] [Top]
我把它放到事件中还是不行啊!
如下:

############################writed by icgre#############################
import dbi, odbc
from Tkinter import *
import pymqi, CMQC, sys, os, string,sys
from init import initdata
from time import strftime,sleep
class panel(Frame):
def __init__(self,initlabel=""):
Frame.__init__(self)
self.pack(expand=YES,fill=BOTH)
self.master.title="Message pass managerV1.0"
self.master.geometry("800x300")
self.source=StringVar()
self.text1=Entry(self,name="text1",textvariable=self.source)
self.source.set("")
self.text1.bind("<Return>",self.action)
self.text1.pack()
self.labelvalue=StringVar()
self.label1=Label(self,textvariable=self.labelvalue)
self.labelvalue.set(initlabel)
self.label1.pack()
self.button1=Button(self,text="O k",command=self.queding)
self.button1.pack()
self.button2=Button(self,text="Cancel",command=self.quxiao)
self.button2.pack()
self.button3=Button(self,text='test me')
self.button3.bind("<Enter>",self.link('1'))
self.button3.pack()
def link(self,order_id):
odbcname=initdata().odbcname
user=initdata().user
password=initdata().password
dbc = odbc.odbc(odbcname+"/"+user+"/"+password)
sql="select * from change_table where order_name="+order_id
crsr = dbc.cursor()
crsr.execute(sql)
result = crsr.fetchall()
sql1=result[0][2]
crsr = dbc.cursor()
crsr.execute(sql1)
result1 = crsr.fetchall()
for i in result1:
str=""
for s in range(len(crsr.description)):
str=str+i[s]+"@"

self.putmessage(initdata().channel,initdata().host,initdata().port,initdata().quemgr,i
nitdata().queue,str)
def putmessage(self,channel,host,port,quemgr,queue,message):
arg_array_size=len(message)
host=host.upper()
quemgr=quemgr.upper()
queue=queue.upper()
command=channel+"/TCP/"+host+"("+port+")"
os.environ['MQSERVER'] =command
os.environ['CCSID'] ="1381"
qmgr = pymqi.QueueManager()
putQ= pymqi.Queue(qmgr,queue)
counter=0
while counter < arg_array_size:
putQ.put(message[counter])
print "Sent Message :",message[counter]
counter = counter +1
def action(self,event):
print "212112"
def queding(self):
source=self.source.get()
if len(source)<>0:

self.putmessage(initdata().channel,initdata().host,initdata().port,initdata().quemgr,i
nitdata().queue,source)
labelvalue="putmessage '"+source+"' successfully! time
is:"+strftime("%Y%m%d%H%M%S")+" "
self.labelvalue.set(labelvalue)
string1="j"
filepath=sys.prefix+string1[0]+"putmessage.log"
file=open(filepath,'a')
file.write("putmessage '"+source+"' successfully! time
is:"+strftime("%Y%m%d%H%M%S")+" ")
file.close()
else:
labelvalue="please input the message! time is:"+strftime("%Y%m%d%H%M%S")+" "
self.labelvalue.set(labelvalue)
string1="j"
filepath=sys.prefix+string1[0]+"putmessage.log"
file=open(filepath,'a')
file.write("Error! The Message Is Null! time is:"+strftime("%Y%m%d%H%M%S")+" ")
file.close()
def quxiao(self):
self.source.set('')
if __name__=="__main__":
panel().mainloop()

还是一进页面就执行!请指教!
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: limodou    Posted: 2005-11-15 18:01    Length: 216 byte(s)
[Original] [Print] [Top]
self.button3.bind("<Enter>",self.link('1'))
这行对事件的绑定不是,这是对self.link的一个调用,应该是:

self.button3.bind("<Enter>",self.link)
----
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: icgre    Posted: 2005-11-16 14:45    Length: 756 byte(s)
[Original] [Print] [Top]
请问一下!如果我想用一个死循环来刷新页面的信息怎么做啊!比如
while 1:
print "1212"
time.sleep(10)
labelvalue=labelvalue+"2121221"
self.labelvalue.set(labelvalue)
来实现页面上label的页面变化!我原来想用点击按钮事件来实现!但是按钮一点就没反映了!因为陷入了死循环,所以不知如何结局!请高手指教如何完成这个功能!
另外您有没有两个py页面之间参数传递的例子啊!我不知道py能不能做到想web页面那样
通过<form name="form1" action="next_page">
<input type="hidden" name="canshu1" value="test">
</form>
来实现两个页面间参数的传递!请高手指教!最好有实例!
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: limodou    Posted: 2005-11-16 20:28    Length: 202 byte(s)
[Original] [Print] [Top]
那使用线程就可以了。但刷新时应该转到主线程上。tk不熟,在wxPython可以使用timer来做。

两个页面?是两个python程序吧。可以创建一个公共的模块,比如conf.py,两个都导入它,用它来传递就行了。
----
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: passworld    Posted: 2005-11-17 00:57    Length: 80 byte(s)
[Original] [Print] [Top]
现在很少人用 Tkinter 了,好象可以用 widget.after(timeout, func, *args)
----
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: icgre    Posted: 2005-11-17 09:10    Length: 165 byte(s)
[Original] [Print] [Top]
请问一下!现在用python编辑界面的,一般用什么工具!我是从参考书上,看到Tkinter的,因为它的资料好像很多的样子,所以就练习了一下!请高手推荐一两种python的界面工具好吗?
[Original] [Print] [Top]
Subject: Re: 请教高手!
Author: limodou    Posted: 2005-11-17 09:46    Length: 75 byte(s)
[Original] [Print] [Top]
个人推荐先从wxPython入手,当然还有pygtk, pyqt。但wxPython安装和学习都方便。
----
[Original] [Print] [Top]
« Previous thread
[精华] 修改了一下readline, 现在ipython可以在windows下输入中文了
Python 编 程
5
Next thread »
[精华] python程序如何改变当前进程的优先级?
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:10:59, cost 0.093948125839233 ms.