Access from one class to methode of other class

2005-05-26 Thread VK
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I 
get error NameError: global name 'd' is not defined. How do I get access 
to d.entry.insert() method of class 1

class 1:
self.entry = Entry(self.entryframe)
self.entry.pack()

self.button = Button(command = self.callclass2window)

def callclass2window
c = 2()


class 2:
def ins(self)
d.entry.insert(variable)


d = 1()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access from one class to methode of other class

2005-05-26 Thread VK
> I don't know if your're actually calling the classes '1' and '2', but
> that's a really bad idea!
> 
> 
>>class 2:
>>   def ins(self)
>>   d.entry.insert(variable)
> 
> 
> This is probably where you're getting the NameError. d is not defined,
> so calling d.entry will generate an error.
> 
> Reidar
> 

What is d = 1() in my example then? And how do I solve this problem?
ч
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Access from one class to methode of other class

2005-05-26 Thread VK
> VK wrote:
> 
>>Hi, all!
>>
>>In my programm i have to insert a variable from class 2 to class 1 and I
>>get error NameError: global name 'd' is not defined. 
> 
> 
> Looking at your code snippet, I think you have a lot of other errors
> before.
> 
> 
>>class 1:
>>   self.entry = Entry(self.entryframe)
> 
> NameError : self is not defined
> 
> etc...
> 

That is not real code, only dummy describing the problem
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access from one class to methode of other class

2005-05-26 Thread VK
> On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
> declaimed the following in comp.lang.python:
> 
> 
>>Hi, all!
>>
>>In my programm i have to insert a variable from class 2 to class 1 and I 
>>get error NameError: global name 'd' is not defined. How do I get access 
>>to d.entry.insert() method of class 1
>>
>>class 1:
> 
>Does Python even allow numeric class names?

:-D don't know

> 
>   REAL code, stripped to the minimum that duplicates your problem,
> is always better than pseudo-code...

I thought that is it...

> 
> 
>>self.entry = Entry(self.entryframe)
>>self.entry.pack()
>>
>>self.button = Button(command = self.callclass2window)
>>
>>def callclass2window
>>  c = 2()
>>
>>
>>class 2:
>>def ins(self)
> 
>   NO : ???
> 
> 
>>  d.entry.insert(variable)
>>
>>
>>d = 1()
> 
> 
>   What, might I ask, does .insert() /do/ for an Entry() object?

That insert text into entry object.

> 
>   As far as I can tell, "class 1" is creating some GUI button.
> Pressing that button invokes your callclass2window(), which creates a
> new "class 2" instance, and then throws it away.

Yes, exactly

> 
>   Give us code that we can /run/ and we might be able to give you
> an answer...

I try:

from Tkinter import *

class First:
 def __init__(self):
 self.root = Tk()  # create window contents as children to 
root..
 self.entryframe = Frame(self.root)
 self.entryframe.pack(fill=BOTH,expand=1)

 self.entry = Entry(self.entryframe)
 self.entry.pack(side=TOP,expand=1,fill=BOTH)
 self.entry.focus()
 self.entry.bind('',(lambda event: self.fetch())) # 
on enter key

 self.button = 
Button(self.entryframe,text="Call",command=self.getvar)
 self.button.pack(side=LEFT,expand=YES,fill=BOTH)

 self.root.mainloop()

 def fetch(self):
 print 'Input => "%s"' % self.entry.get() # get text form entry

 def getvar(self,event=0):
 c=Second(self,self.root)



class Second:
 def __init__(self,parent,s="thing"):
 self.root = Tk()
 self.ent = Entry(self.root)
 self.ent.pack()
 self.btn = Button(self.root,text='Fetch',command=self.fetch)
 self.btn.pack(side=RIGHT)
 def fetch(self):
 text = self.ent.get() # get text form entry in this window
 d.entry.insert(0, text)# must insert in other window

d = First() #First window
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access from one class to methode of other class

2005-05-26 Thread VK
Kent Johnson wrote:
> VK wrote:
> 
>>> On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
>>> declaimed the following in comp.lang.python:
>>>
>>>
>>>> Hi, all!
>>>>
>>>> In my programm i have to insert a variable from class 2 to class 1 
>>>> and I get error NameError: global name 'd' is not defined. How do I 
>>>> get access to d.entry.insert() method of class 1
> 
> 
>>
>> from Tkinter import *
>>
>> class First:
>> def __init__(self):
>> self.root = Tk()  # create window contents as children to 
>> root..
>> self.entryframe = Frame(self.root)
>> self.entryframe.pack(fill=BOTH,expand=1)
>>
>> self.entry = Entry(self.entryframe)
>> self.entry.pack(side=TOP,expand=1,fill=BOTH)
>> self.entry.focus()
>> self.entry.bind('',(lambda event: self.fetch())) # 
>> on enter key
>>
>> self.button = 
>> Button(self.entryframe,text="Call",command=self.getvar)
>> self.button.pack(side=LEFT,expand=YES,fill=BOTH)
>>
>> self.root.mainloop()
>>
>> def fetch(self):
>> print 'Input => "%s"' % self.entry.get() # get text form 
>> entry
>>
>> def getvar(self,event=0):
>> c=Second(self,self.root)
>>
>>
>>
>> class Second:
>> def __init__(self,parent,s="thing"):
>> self.root = Tk()
>> self.ent = Entry(self.root)
>> self.ent.pack()
>> self.btn = Button(self.root,text='Fetch',command=self.fetch)
>> self.btn.pack(side=RIGHT)
>> def fetch(self):
>> text = self.ent.get() # get text form entry in this window
>> d.entry.insert(0, text)# must insert in other window
>>
>> d = First() #First window
> 
> 
> The problem is that First.__init__() never returns so the instance of 
> First is never bound to d. Take the line
>   self.root.mainloop()
> out of First.__init__() and and the line
> d.root.mainloop()
> 
> at the end of the program and it will work as you expect.
> 
> Kent

O, God! It works! Thousend of thanks!

By the way, the second window appears not activ, is there an option to 
make it activ on start?

Reg,VK
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting value of radiobutton trouble

2005-05-28 Thread VK
Hi!
What I'm missing in following code? Cannot get the values of 
radiobuttons. Starting only one class (GetVariant), it works. When I put 
two classes together, it doesn't.
Regards, VK

from Tkinter import *
class GetVariant:
 def __init__(self):
 self.root = Tk()
 self.mainframe = Frame(self.root,bg="yellow")
 self.mainframe.pack(fill=BOTH,expand=1)

 self.firstframe = Frame(self.mainframe,bg="red")
 self.firstframe.pack(side=BOTTOM,expand=1)

 global v
 v = StringVar()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
1", variable=v, value="Variant 1")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton.select()
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
2", variable=v, value="Variant 2")
 self.radiobutton.pack(side=TOP,anchor=W)
 self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
3", variable=v, value="Variant 3")
 self.radiobutton.pack(side=TOP,anchor=W)



 self.secondframe = Frame(self.mainframe,bg="blue")
 self.secondframe.pack()
 self.var = Button(self.secondframe,text="What 
Variant",command=self.call)
 self.var.pack(expand=1,side=BOTTOM)



 def call(self):
 self.variant = v.get()
 print 'Input => "%s"' % self.variant

class OneButton:
 def __init__(self):
 self.root = Tk()
 Button(self.root,text="click me",command=self.getvar).pack()
 def getvar(self):
 a=GetVariant()

d = OneButton()
d.root.mainloop()


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Hi, 
> 
> I think your second call to Tk() does it: this works although the look is
> different:
> 
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self):
>  self.root = Tk()
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
>  global v
>  v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 1", variable=v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 2", variable=v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text= "Variant 
> 3", variable=v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What 
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>      a=GetVariant()
> 
> d = OneButton()
> d.root.mainloop()
> 
> 
> 
> 
> VK wrote:
> 
> 
>>Hi!
>>What I'm missing in following code? Cannot get the values of
>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>two classes together, it doesn't.
>>Regards, VK
>>
>>from Tkinter import *
>>class GetVariant:
>> def __init__(self):
>> self.root = Tk()
>> self.mainframe = Frame(self.root,bg="yellow")
>> self.mainframe.pack(fill=BOTH,expand=1)
>>
>> self.firstframe = Frame(self.mainframe,bg="red")
>> self.firstframe.pack(side=BOTTOM,expand=1)
>>
>> global v
>> v = StringVar()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>1", variable=v, value="Variant 1")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton.select()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>2", variable=v, value="Variant 2")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>3", variable=v, value="Variant 3")
>> self.radiobutton.pack(side=TOP,anchor=W)
>>
>>
>>
>> self.secondframe = Frame(self.mainframe,bg="blue")
>> self.secondframe.pack()
>> self.var = Button(self.secondframe,text="What
>>Variant",command=self.call)
>> self.var.pack(expand=1,side=BOTTOM)
>>
>>
>>
>> def call(self):
>> self.variant = v.get()
>> print 'Input => "%s"' % self.variant
>>
>>class OneButton:
>> def __init__(self):
>> self.root = Tk()
>> Button(self.root,text="click me",command=self.getvar).pack()
>> def getvar(self):
>> a=GetVariant()
>>
>>d = OneButton()
>>d.root.mainloop()
> 
> 

Sorry, but I don't get it. There is no deference between my code and 
your answer. I'm beginner...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Sorry,
> 
> I still had your code in my clipboard :-) here goes:

So, your code works, but I need, that first window calls another 
separate window. In your programm they stick together.
Reg, VK

> 
> 
> 
> from Tkinter import *
> class GetVariant(Frame):
>  def __init__(self,p):
>  self.root = p
>  self.mainframe = Frame(self.root,bg="yellow")
>  self.mainframe.pack(fill=BOTH,expand=1)
> 
>  self.firstframe = Frame(self.mainframe,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
> 
>  self.v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
> variable=self.v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
> variable=self.v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
> variable=self.v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.mainframe,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  print dir(self.v)
>  self.variant = self.v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton(Frame):
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  print 'HRE'
>  a=GetVariant(self.root)
> 
> d = OneButton()
> d.root.mainloop()
> 
> 
> 
> 
> 
> 
> Philippe C. Martin wrote:
> 
> 
>>Hi,
>>
>>I think your second call to Tk() does it: this works although the look is
>>different:
>>
>>
>>from Tkinter import *
>>class GetVariant:
>> def __init__(self):
>> self.root = Tk()
>> self.mainframe = Frame(self.root,bg="yellow")
>> self.mainframe.pack(fill=BOTH,expand=1)
>>
>> self.firstframe = Frame(self.mainframe,bg="red")
>> self.firstframe.pack(side=BOTTOM,expand=1)
>>
>> global v
>> v = StringVar()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>1", variable=v, value="Variant 1")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton.select()
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>2", variable=v, value="Variant 2")
>> self.radiobutton.pack(side=TOP,anchor=W)
>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>3", variable=v, value="Variant 3")
>> self.radiobutton.pack(side=TOP,anchor=W)
>>
>>
>>
>> self.secondframe = Frame(self.mainframe,bg="blue")
>> self.secondframe.pack()
>> self.var = Button(self.secondframe,text="What
>>Variant",command=self.call)
>> self.var.pack(expand=1,side=BOTTOM)
>>
>>
>>
>> def call(self):
>> self.variant = v.get()
>> print 'Input => "%s"' % self.variant
>>
>>class OneButton:
>> def __init__(self):
>> self.root = Tk()
>> Button(self.root,text="click me",command=self.getvar).pack()
>> def getvar(self):
>> a=GetVariant()
>>
>>d = OneButton()
>>d.root.mainloop()
>>
>>
>>
>>
>>VK wrote:
>>
>>
>>>Hi!
>>>What I'm missing in following code? Cannot get the values of
>>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>>two classes together, it doesn't.
>>>Regards, VK
>>>
>>>from Tkinter import *
>>>class GetVariant:
>>> def __init__(self):
>>> self.root = Tk()
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>>

Re: Copy paste in entry widget

2005-05-28 Thread VK
Skip Montanaro wrote:
> Michael> is copy, paste, cut of selection possible in entry widget? Docs
> Michael> say selection must be copied by default, in my programm it
> Michael> doesn't work.
> 
> What platform?  What GUI toolkit?
> 

Linux, Windows. TkInter, Pmw.
I've already implemented this with code under my message, but "cut"
copies entrytext, without deleting selection. Any ideas

def copy(self):
 global copied
 if self.entry.selection_present():
self.entry.clipboard_clear()
copied = self.entry.selection_get()
 self.entry.bell()
 def paste(self):
 self.entry.insert(END, copied)
 def cut(self):
 global copied
 self.entry.clipboard_clear()
 if self.entry.selection_present():
 copied = self.entry.selection_get()
 self.entry.selection_clear()
 self.entry.bell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting value of radiobutton trouble

2005-05-28 Thread VK
Philippe C. Martin wrote:
> Then I guess you need a TopLevel widget instead:
> 
> 
> (I still suggest you look at wxPython)
> 
> 
> from Tkinter import *
> class GetVariant:
>  def __init__(self,p):
>  self.root = p
> 
>  self.firstframe = Frame(self.root,bg="red")
>  self.firstframe.pack(side=BOTTOM,expand=1)
> 
> 
>  self.v = StringVar()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
> variable=self.v, value="Variant 1")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton.select()
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
> variable=self.v, value="Variant 2")
>  self.radiobutton.pack(side=TOP,anchor=W)
>  self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
> variable=self.v, value="Variant 3")
>  self.radiobutton.pack(side=TOP,anchor=W)
> 
> 
> 
>  self.secondframe = Frame(self.root,bg="blue")
>  self.secondframe.pack()
>  self.var = Button(self.secondframe,text="What
> Variant",command=self.call)
>  self.var.pack(expand=1,side=BOTTOM)
> 
> 
> 
>  def call(self):
>  self.variant = self.v.get()
>  print 'Input => "%s"' % self.variant
> 
> class OneButton:
>  def __init__(self):
>  self.root = Tk()
>  Button(self.root,text="click me",command=self.getvar).pack()
>  def getvar(self):
>  self.mainframe = Toplevel(bg="yellow")
>  a=GetVariant(self.mainframe)
> 
> d = OneButton()
> d.root.mainloop()
> 
> VK wrote:
> 
> 
>>Philippe C. Martin wrote:
>>
>>>Sorry,
>>>
>>>I still had your code in my clipboard :-) here goes:
>>
>>So, your code works, but I need, that first window calls another
>>separate window. In your programm they stick together.
>>Reg, VK
>>
>>
>>>
>>>
>>>from Tkinter import *
>>>class GetVariant(Frame):
>>> def __init__(self,p):
>>> self.root = p
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>>
>>> self.v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 1",
>>>variable=self.v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 2",
>>>variable=self.v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text="Variant 3",
>>>variable=self.v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> print dir(self.v)
>>> self.variant = self.v.get()
>>> print 'Input => "%s"' % self.variant
>>>
>>>class OneButton(Frame):
>>> def __init__(self):
>>> self.root = Tk()
>>> Button(self.root,text="click me",command=self.getvar).pack()
>>> def getvar(self):
>>> print 'HRE'
>>> a=GetVariant(self.root)
>>>
>>>d = OneButton()
>>>d.root.mainloop()
>>>
>>>
>>>
>>>
>>>
>>>
>>>Philippe C. Martin wrote:
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>I think your second call to Tk() does it: this works although the look is
>>>>different:
>>>>
>>>>
>>>
>>>>from Tkinter import *
>>>
>>>>class GetVariant:
>>>>def __init__(self):
>>>>s

Re: Getting value of radiobutton trouble

2005-05-29 Thread VK
Philippe C. Martin wrote:
> PS: Since your starting with TKinter, and although I do not know what your
> goal is, I suggest you take a look at wxPython: it is _wonderfull_ ! (no
> offence to TCL/TK)
> 
> Regards,
> 
> Philippe
> 
> 
> 
> 
> 
> 
> VK wrote:
> 
> 
>>Philippe C. Martin wrote:
>>
>>>Hi,
>>>
>>>I think your second call to Tk() does it: this works although the look is
>>>different:
>>>
>>>
>>>from Tkinter import *
>>>class GetVariant:
>>> def __init__(self):
>>> self.root = Tk()
>>> self.mainframe = Frame(self.root,bg="yellow")
>>> self.mainframe.pack(fill=BOTH,expand=1)
>>>
>>> self.firstframe = Frame(self.mainframe,bg="red")
>>> self.firstframe.pack(side=BOTTOM,expand=1)
>>>
>>> global v
>>> v = StringVar()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>1", variable=v, value="Variant 1")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton.select()
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>2", variable=v, value="Variant 2")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>3", variable=v, value="Variant 3")
>>> self.radiobutton.pack(side=TOP,anchor=W)
>>>
>>>
>>>
>>> self.secondframe = Frame(self.mainframe,bg="blue")
>>> self.secondframe.pack()
>>> self.var = Button(self.secondframe,text="What
>>>Variant",command=self.call)
>>> self.var.pack(expand=1,side=BOTTOM)
>>>
>>>
>>>
>>> def call(self):
>>> self.variant = v.get()
>>> print 'Input => "%s"' % self.variant
>>>
>>>class OneButton:
>>> def __init__(self):
>>> self.root = Tk()
>>> Button(self.root,text="click me",command=self.getvar).pack()
>>> def getvar(self):
>>> a=GetVariant()
>>>
>>>d = OneButton()
>>>d.root.mainloop()
>>>
>>>
>>>
>>>
>>>VK wrote:
>>>
>>>
>>>
>>>>Hi!
>>>>What I'm missing in following code? Cannot get the values of
>>>>radiobuttons. Starting only one class (GetVariant), it works. When I put
>>>>two classes together, it doesn't.
>>>>Regards, VK
>>>>
>>>
>>>>from Tkinter import *
>>>
>>>>class GetVariant:
>>>>def __init__(self):
>>>>self.root = Tk()
>>>>self.mainframe = Frame(self.root,bg="yellow")
>>>>self.mainframe.pack(fill=BOTH,expand=1)
>>>>
>>>>self.firstframe = Frame(self.mainframe,bg="red")
>>>>self.firstframe.pack(side=BOTTOM,expand=1)
>>>>
>>>>global v
>>>>v = StringVar()
>>>>self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>>1", variable=v, value="Variant 1")
>>>>self.radiobutton.pack(side=TOP,anchor=W)
>>>>self.radiobutton.select()
>>>>self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>>2", variable=v, value="Variant 2")
>>>>self.radiobutton.pack(side=TOP,anchor=W)
>>>>self.radiobutton = Radiobutton(self.firstframe,text= "Variant
>>>>3", variable=v, value="Variant 3")
>>>>self.radiobutton.pack(side=TOP,anchor=W)
>>>>
>>>>
>>>>
>>>>self.secondframe = Frame(self.mainframe,bg="blue")
>>>>self.secondframe.pack()
>>>>self.var = Button(self.secondframe,text="What
>>>>Variant",command=self.call)
>>>>self.var.pack(expand=1,side=BOTTOM)
>>>>
>>>>
>>>>
>>>>def call(self):
>>>>self.variant = v.get()
>>>>print 'Input => "%s"' % self.variant
>>>>
>>>>class OneButton:
>>>>def __init__(self):
>>>>self.root = Tk()
>>>>Button(self.root,text="click me",command=self.getvar).pack()
>>>>def getvar(self):
>>>>a=GetVariant()
>>>>
>>>>d = OneButton()
>>>>d.root.mainloop()
>>>
>>>
>>Sorry, but I don't get it. There is no deference between my code and
>>your answer. I'm beginner...
> 
> 

Thanks for your help! Toplevel made the job.
Reg. VK
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy paste in entry widget

2005-05-29 Thread VK
Michael Onfrek wrote:
> Hi,
> is copy, paste, cut of selection possible in entry widget? Docs say
> selection must be copied by default, in my programm it doesn't work.
> Regards, M.O.
> 
Hear it is

 def paste(self):
 self.entry.event_generate('')
 def cut(self):
 self.entry.event_generate('')
 def copy(self):
 self.entry.event_generate('')
-- 
http://mail.python.org/mailman/listinfo/python-list


Entry scroll doesn't work

2005-05-29 Thread VK
Hi!
Can entry widget be scrolled?
VK

TypeError: xview() takes exactly 2 arguments (4 given)

Code:



from Tkinter import *
class ScrollEntry:
 def __init__(self):
 self.root = Tk()
 self.scrollbar = Scrollbar(self.root,orient=HORIZONTAL,)
 self.entry = Entry(self.root,xscrollcommand=self.scrollbar.set)
 self.entry.focus()
 self.entry.pack(side=TOP,fill=X)
 self.scrollbar.pack(fill=X)
 self.scrollbar.config(command=self.entry.xview)
 self.entry.config()


a=ScrollEntry()
a.root.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Entry scroll doesn't work

2005-05-29 Thread VK
VK wrote:
> Hi!
> Can entry widget be scrolled?
> VK
> 
> TypeError: xview() takes exactly 2 arguments (4 given)
> 
> Code:
> 
> 
> 
> from Tkinter import *
> class ScrollEntry:
> def __init__(self):
> self.root = Tk()
> self.scrollbar = Scrollbar(self.root,orient=HORIZONTAL,)
> self.entry = Entry(self.root,xscrollcommand=self.scrollbar.set)
> self.entry.focus()
> self.entry.pack(side=TOP,fill=X)
> self.scrollbar.pack(fill=X)
> self.scrollbar.config(command=self.entry.xview)
> self.entry.config()
> 
> 
> a=ScrollEntry()
> a.root.mainloop()

Already found:  :)

http://infohost.nmt.edu/tcc/help/pubs/tkinter/entry-scrolling.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to restrict lenght of entry widget to certain number of character

2005-06-02 Thread VK
Peter Otten wrote:
> Michael Onfrek wrote:
> 
> 
>>import Tkinter as tk
>>
>>Hi! Can you explain what line above mean?
>>
>>I also found : http://effbot.org/zone/tkinter-entry-validate.htm
>>
>>It works for me, but I not really  understand how? :)
> 
> 
>>>import Tkinter as tk
> 
> 
> Make objects defined in Tkinter available under the tk prefix.
> E. g. to access an Entry you can do 'tk.Entry'. Had you imported it 
> 'import Tkinter' you would have to do 'Tkinter.Entry' instead. So you
> are saving a few keystrokes. Doing 'from Tkinter import *' saves you still
> more keystrokes but is considered bad style except for demonstration
> purposes.
> 
> 
>>>var = tk.StringVar()
>>>entry = tk.Entry(root, textvariable=var)
> 
> 
> Create a StringVar and connect it to the Entry widget. Any changes the user
> makes in the Entry are reflected in the StringVar's value which can be
> accessed with its get() method.
> 
> 
>>>max_len = 5
>>>def on_write(*args):
>>>s = var.get()
>>>if len(s) > max_len:
>>>var.set(s[:max_len])
> 
> 
> Define a function that doesn't care about the arguments passed to it. It 
> reads the current value of the StringVar 'var' and, if necessary, trims it
> to 'max_len_' characters.
> 
> 
>>>var.trace_variable("w", on_write)
> 
> 
> Tell the StringVar to call the function on_write() every time its value is
> changed. So every time the user edits the data in the Entry, in turn the
> Entry changes the data of the StringVar, which calls the on_write()
> function which may or may not change the StringVar -- and that change is
> reflected in what the Entry displays. This smells like an endless loop, but
> so far we seem to be lucky...
> 
> If you look again at Fredrik Lundh's ValidatingEntry, you will find all the
> elements explained above packed nicely into one class, with the extra
> refinement that he keeps another copy of the value which is used to restore
> the old state when the new value is found to be invalid.
> 
> Peter
> 

Thank you, man! You should write an tutorial to Tkinter or something 
like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft's JavaScript doc's newfangled problem

2005-12-24 Thread VK

Xah Lee wrote:
> sometimes in the last few months, apparently Microsoft made changes to
> their JavaScript documentation website:

Their *JScript* documentation website - here's the keyword.

 See:


After the official breakup with IE for Mac OS:


JScript site is now only and exclusively for Internet Explorer 5.5 and
higher under Windows 98 SE and higher.

Any other visitors are out of support and interest of Microsoft - at
least in JScript domain. It is bad and rude, but it is and I'm affraid
it will be.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bind in Tkinter

2005-06-10 Thread VK
Shankar Iyer ([EMAIL PROTECTED]) wrote:
> I have been trying to learn how to associate keyboard events with actions 
> taken by a Python program using Tkinter.  From what I've read online, it 
> seems that this is done with the bind methods.  In one of my programs, I have 
> included the following:
> 
> self.enternumber = Entry(self)
> self.enternumber.bind("",self.quit)
> self.enternumber.pack({"side":"top"})
> 
> It seems to me that, as a result of this code, if the enternumber Entry 
> widget is selected and then the  key is pressed, then the program 
> should quit.  Indeed, it seems that the program does attempt to quit, but 
> instead an error message appears claiming that quit() takes 1 argument but 2 
> are given.  I get the same type of error if I replace self.quit with some 
> function that I have written.  I am not sure how to fix this problem and hope 
> that someone here can spot my error.  Thanks for your help.
> 
> Shankar
> 
> 
Have you defined quit function?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bind in Tkinter

2005-06-10 Thread VK
Shankar Iyer ([EMAIL PROTECTED]) wrote:
> I believe the quit function is built in.  Anyway, I get the same type of 
> error if I substitute a function that I have defined.
> 
> Shankar
> 
> - Original Message -
> From: VK <[EMAIL PROTECTED]>
> Date: Friday, June 10, 2005 4:53 pm
> Subject: Re: bind in Tkinter
> 
> 
>>Shankar Iyer ([EMAIL PROTECTED]) wrote:
>>
>>>I have been trying to learn how to associate keyboard events with 
>>
>>actions taken by a Python program using Tkinter.  From what I've 
>>read online, it seems that this is done with the bind methods.  In 
>>one of my programs, I have included the following:
>>
>>>self.enternumber = Entry(self)
>>>self.enternumber.bind("",self.quit)
>>>self.enternumber.pack({"side":"top"})
>>>
>>>It seems to me that, as a result of this code, if the enternumber 
>>
>>Entry widget is selected and then the  key is pressed, then 
>>the program should quit.  Indeed, it seems that the program does 
>>attempt to quit, but instead an error message appears claiming that 
>>quit() takes 1 argument but 2 are given.  I get the same type of 
>>error if I replace self.quit with some function that I have 
>>written.  I am not sure how to fix this problem and hope that 
>>someone here can spot my error.  Thanks for your help.
>>
>>>Shankar
>>>
>>>
>>
>>Have you defined quit function?
>>-- 
>>http://mail.python.org/mailman/listinfo/python-list
>>
> 
> 

for built-in you don't need *self*

If you define yours, try

def quit(self,event=0)
-- 
http://mail.python.org/mailman/listinfo/python-list