codice:
from wxPython.wx import *
import socket


HOST = "127.0.0.1"
PORT = 80


class MiaApp(wxApp):
	def OnInit(self):
		dlg = wxDialog(None, -1, "", size=(500,450))

		txt4 = wxTextCtrl(dlg, -1, "Testo di prova", wxPoint(1, 1), wxSize(350,300), style=wxTE_MULTILINE)

		data2 = txt4.GetValue()

		ID_BTN = wxNewId()
		btn = wxButton(dlg, ID_BTN, "Premimi!", wxPoint(360,1))
		EVT_BUTTON(self, ID_BTN, self.OnClick)

		dlg.ShowModal()
		dlg.Destroy()
		return 1

	def OnClick(self, event):
		connessione = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		connessione.connect((HOST, PORT))
		connessione.send('GET /blog/check.php?pass='+data2+' HTTP/1.x \n\n')
		data = connessione.recv(1024)
		connessione.close()

		wxMessageBox(data)


app = MiaApp()
app.MainLoop()

Questo script mi dà errore quando premo sul pulsante "Premimi!", restituendomi:
NameError: global name 'data2' is not defined
Quindi il problema è rendere globale la variabile data2, in modo da poterla utilizzare nell'evento "OnClick".
Ma come si fa?


Grazie