Hi,
Im trying to write an irc client with python. This is its login page(i hope it will be)

#!usr/bin/env python
# -*- coding: utf8 -*-

import gtk, sys, socket

class PyApp(gtk.Window):
	
	def con(self):
		iserver = self.entry.get_text()
		inick = self.entry2.get_text()
		room = self.entry3.get_text()
		password = self.entry4.get_text()
		
		socket.server = iserver
		socket.nick = inick
		socket.channel = ichannel
		irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
		irc.connect((iserver, 6667))
		irc.send('NICK %s\r\n' % inick)
		irc.send('USER X 0 * : gms\r\n')
		irc.send('JOIN %s\r\n' % ichannel)
		
	def __init__(self):
		super(PyApp, self).__init__()
		
		self.set_title("Gms-irc")
		self.set_size_request(360, 200)
		self.set_position(gtk.WIN_POS_CENTER)
		
		fixed = gtk.Fixed()		
		
		self.label = gtk.Label("Server:")
		fixed.put(self.label, 20, 20)
		self.label = gtk.Label("Nick:")
		fixed.put(self.label, 20, 50)
		self.label = gtk.Label("Room:")
		fixed.put(self.label, 20, 80)
		self.label = gtk.Label("Password:")
		fixed.put(self.label, 20, 110)
		
		self.entry = gtk.Entry()
		fixed.put(self.entry, 140, 20)
		self.entry2 = gtk.Entry()
		fixed.put(self.entry2, 140, 50)
		self.entry3 = gtk.Entry()
		fixed.put(self.entry3, 140, 80)
		self.entry4 = gtk.Entry()
		fixed.put(self.entry4, 140, 110)
		
		self.btn1 = gtk.Button("Connect!")
		self.btn1.connect("clicked", self.con)
		
		fixed.put(self.btn1, 80, 150)
		
		self.add(fixed)
		self.show_all()

PyApp()
gtk.main()

its not finished yet, when i run script i take error that "TypeError: con() takes exactly 1 argument (2 given)" couldnt fix that. can any1 help me?

Recommended Answers

All 4 Replies

You need to change the definition of con() to support the event details that get automatically passed to any bound method.

The new definition should look like this:

def con(self, event=None):

Note that I initialized event to None so that you can still call it yourself without needing to supply an event class.

hmm trying to understand :) when i make it like you write it dont give that error but still cant login to irc :S

I suggest verifying your login method line-by-line in the interpreter before implementing into the function.

Adding the event is simply a requirement that gtk enforces. Any method bound to a button press or key stroke will need to accept an event as input.

i see ty :)

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.