Re: Noob question: Is all this typecasting normal?
Anyone have something to say about the userio stuff? (If you're going to post something about my coding style, I invite you to do something infinitely more useful: write crapToPep8.py {or is it crap_to_pep8?} to satisfy your sick fetish for consistency.) -- http://mail.python.org/mailman/listinfo/python-list
Re: ResponseNotReady exception
http://www.python.org/phpvuln.txt Error 404: File Not Found The URL you requested was not found on this server. -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob question: Is all this typecasting normal?
Any more word on userio? None yet, I'm afraid. Should've started a different thread for it - but it's stuck here (in obscurity) forever xd. -- http://mail.python.org/mailman/listinfo/python-list
Port of python stdlib to other languages.
Have there been ports of the Python standard library to other languages? I would imagine using pickle, urllib, and sys in C (with pythonic naming conventions) would be easier than using other libraries to do the same thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Port of python stdlib to other languages.
AFAIK not. You could try elmer Elmer looks very interesting, but not really what I was getting at. What do you need C for anyway? Or, to put it the other way round - why not expose whatever you need in C as python extension, and write your app in Python? I'm not looking to write a Python app atm. Just curious if someone had started a project like this, to, say, make Python users more comfortable using other languages (for whatever reason), or allow other people to try python-like code in their language to see if it suits them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob question: Is all this typecasting normal?
You might better do bet = int(raw_input(Enter your bet)) because then you don't need to later on convert bet again and again. This is all fine until you give it to an end-user. This is what I picture: $ ./script.py Enter your bet: $10 .. or perhaps ten, all, or a jillion other tainted inputs. Python will try to cast these strings, but will slap you with a ValueError instead (an error of some sort, at least). There needs to be a user_io or sanitize module in the standard library to take care of this stuff. Like: import userio logic = userio.userio() number = logic.getNumeric(blah: ) # will offer the user a re-do in case of bad input number = logic.forceGetNumeric(Enter your bet!: ) # even if input is tainted, will return some number text = logic.getText(blargh: ) # return all text text = logic.setValidText([A-Za-z]) text = logic.forceGetText(blargh: ) # return some text, strips invalid chars ... but there isn't, as far as I know. -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob question: Is all this typecasting normal?
If there were, I would expect it to conform with PEP 8 (get those ugly camelCase names outta there :-) haha, please forgive me. I'll try and think of some more creative names. atm, I've got a chem final to study for. I'll probably post something resembling useful code tomorrow morning. until then, int(input()) away! -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob question: Is all this typecasting normal?
etc etc ... IOW consider not biting off more than you can chew. It's possible that I am, but where's the fun without the risk? Good thinking in your post though! I will add get_date at some point, and I've modified get_numeric already. All-right, the moment you've all been waiting for: - http://docs.google.com/View?docid=dgsp7w2t_2gwf447g8 - Provides: 1) user_io.user_io -- get_text(msg) -- filter_get(msg, valid_chars) -- get_numeric(msg) -- bully_numeric(msg) 2) user_io.progress_bar -- ping() -- stop() Read the doc-strings for details. I know it isn't perfect, so just yell at me on this thread if you don't like something and I'll try to fix it. Actually, I'd rather you fix it yourself and THEN yell at me to update the module. have fun! -- http://mail.python.org/mailman/listinfo/python-list
Re: Ideas to optimize this getitem/eval call?
What do you mean by 'fail'? you have; :: self.codes = {} so :: try: ::return eval(self.codes[expr], self.globals, self.locals) will always return an exception the first time (if this is what you're referring to). -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob question: Is all this typecasting normal?
Unless you explicitly *never* intend sharing your code with *anyone*, it's best to code all your Python code in accordance with PEP 8 anyway. Well said. Let's bury the puppy already. Anyone have something to say about the userio stuff? -- http://mail.python.org/mailman/listinfo/python-list
Re: Netbeans Early Access and Python3
Netbeans is a very polished IDE. I just tried the Python EA plugin, however, and it does not have 3.x support as of now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft's JavaScript doc's newfangled problem
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: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/a4a1e9736dc8fa11/9f41a436cf9d8f44 After the official breakup with IE for Mac OS: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/e85ccf3d8da2/518b0949b792#518b0949b792 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: How to restrict lenght of entry widget to certain number of character
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: Getting value of radiobutton trouble
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
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('Control-v') def cut(self): self.entry.event_generate('Control-x') def copy(self): self.entry.event_generate('Control-c') -- http://mail.python.org/mailman/listinfo/python-list
Entry scroll doesn't work
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
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
Getting value of radiobutton trouble
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
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
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) 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: Copy paste in entry widget
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
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): 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
Access from one class to methode of other class
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
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
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
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: shudder 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('Return',(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
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('Return',(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