Hello,
here is a thing, i'm beginner at wxPython ant Pyhton too. I have written small program here is a example:

import wx
import urllib2
import re

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(600,400))
        self.panel=wx.Panel(self)
        
        
        
        self.areaa = wx.TextCtrl(self.panel, pos=(0,10), size=(400, 20))
        self.area = wx.TextCtrl(self.panel, style = wx.MULTIPLE, pos=(0,50), size=(400,250))
        self.pirmas=wx.Button(self.panel, label="Parodyk", pos=(420, 10), size=(100,20))
        self.Bind(wx.EVT_BUTTON, self.aaa, self.pirmas)

    def aaa (self, event):
        
        response = urllib2.urlopen(self.areaa)
        html = response.read()
        failas = open("failas.txt", 'w')
        failas.write(html)
        failas.close()

        failas = open("failas.txt", 'r')
        regex = re.compile ('http://someurl.*?<')
        
        for line in failas:
            g = regex.findall(line)
            for word in g:
                print (word)[:-1]
                  
        failas.close()


app = wx.PySimpleApp()
frm = MyFrame(None, "Simple Program")
frm.Show()
app.MainLoop()

programs starts fine, but then i input something in areaa box i get this error message

Traceback (most recent call last):
  File "C:\Python27\11.py", line 19, in aaa
    response = urllib2.urlopen(self.areaa)
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 384, in open
    protocol = req.get_type()
AttributeError: 'TextCtrl' object has no attribute 'get_type'

What should i change about program to work. I need to input url address and then program grabs it's html and so on..
one more question, how to show the results in area box (that list of links)?

P.S on what highest python version wxpython works?

Thank You.

Recommended Answers

All 3 Replies

shouldn't it be

response = urllib2.urlopen(self.areaa.GetValue())

urlopen does not know anything about wx.TextCtrl widgets.

Check your naming of things and using of empty lines.

You should also let wx handle the suitable size of widgets and not use absolute positioning and sizing (sizers).

Thanks, working good! Yea i know i need to learn those sizers. :) I just experimenting so its a bit messy, sorry :)

P.S maybe someone know anything about other questions?

P.S on what highest python version wxpython works?

2.7 wxpython Roadmap

Just a note dont use findall() in a loop.
findall() iterate through all text it`s given.

g = regex.findall(regex, failas.read())

If you shall iterate through to text,use finditer()

for line in failas:
    for match in regex.finditer(line):
        print (match.group())[:-1]

And print in GUI is most for troubelshoothing.
You wirte to a label text,texbox ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.