切换风格

Wizard Sky California Sunset glow Black Cloud Beige Dragon Lavender NewYear City Snow Flowers London
收藏本站XSS平台字符串转换jsfuck
wxpython程序问题[复制链接]
发表于 2014-9-14 16:15:03 | 显示全部楼层 |!read_mode!
程序能正常运行,但又两个问题:1.点击search后,button按键不恢复原来的样子
2.程序在运行的时候不能随意拖动,拖动程序界面就卡住,待程序运行完成才正常


求讲解


如图:

1.jpg


发表于 2014-9-14 16:42:44 | 显示全部楼层
你这个样子没办法讲解啊 ,编程的问题你要把源码贴出来才行啊
发表于 2014-9-14 16:56:46 | 显示全部楼层
店小二01 发表于 2014-9-14 16:42
你这个样子没办法讲解啊 ,编程的问题你要把源码贴出来才行啊

不好意思忘记啦!代码如下
#coding:utf8
import wx
import simplejson,random
import requests as req
import sys

page = 1
status = 200
class PaintFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "google key search", size = (800, 600))
        pancel = wx.Panel(self,-1)
        searchbutton = wx.Button(pancel,label='search')
        stopbutton = wx.Button(pancel,label='stop')
        self.sch = wx.TextCtrl(pancel,-1,u"请输入关键字")
        self.result = wx.TextCtrl(pancel,-1,style=wx.TE_MULTILINE|wx.HSCROLL|wx.TE_READONLY)
        searchbutton.Bind(wx.EVT_BUTTON, self.search)
        stopbutton.Bind(wx.EVT_BUTTON,self.stop)
        hbox = wx.BoxSizer()
        hbox.Add(self.sch,proportion=1,flag=wx.EXPAND)
        hbox.Add(searchbutton,proportion=0,flag=wx.LEFT,border=5)
        hbox.Add(stopbutton,proportion=0,flag=wx.LEFT,border=5)
        bbox = wx.BoxSizer(wx.VERTICAL)
        bbox.Add(hbox,proportion=0,flag=wx.EXPAND|wx.ALL,border=5)
        bbox.Add(self.result,proportion=1,flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,border=5)
        pancel.SetSizer(bbox)
        

    def search(self, event):
        searchcontent = self.sch.GetValue()
        #self.result.SetValue(searchcontent)
        global page
        global status
        while status == 200:
            headers = {
                       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                       'Accept-Charset': 'gb18030,utf-8;q=0.7,*;q=0.3',
                       'Accept-Encoding': 'gzip,deflate,sdch',
                       'Accept-Language': 'en-US,en;q=0.8',
                       'Connection': 'keep-alive',
                       'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4',
                       'Referer': 'http://www.baidu.com/'
            }
            url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s&rsz=8&start=%s&cr=countryNZ"%(searchcontent,page)
            try:
                HtmlContent = req.get(url, timeout=30, headers=headers).text
                result = simplejson.loads(HtmlContent)
                status = result['responseStatus']
                self.result.AppendText("page:%d" % page)
                try:
                    Urls = result['responseData']['results']
                    for url in Urls:
                            self.result.AppendText(url['url'])
                            self.result.AppendText('\n')
                except:
                    self.result.AppendText('get page error')
                    self.result.AppendText(result['responseDetails'])
                page += 1
            except:
                self.result.AppendText("Time Out or site is not open")
        self.result.AppendText("conut:%d" % (page-2))
    
    def stop(self):
        sys.exit(0)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = PaintFrame(None)
    frame.Show(True)
    app.MainLoop()



发表于 2014-9-17 11:31:52 | 显示全部楼层
@店小二01  能帮我看下,点击停止按钮的时候怎么停止搜索? 需要写个函数做判断,求给点建议
发表于 2014-10-1 16:54:23 | 显示全部楼层

发表于 2014-11-29 11:57:45 | 显示全部楼层
看看吧

代码区

GMT+8, 2019-11-23 08:06

Powered by Discuz! X2

© 2001-2018 Comsenz Inc.

回顶部