Hi all,
I have a little problem.
def tekst_in(self, tag):
tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'}
print tekst_tag[tag]
works fine in my class
But...
def tekst_in(self, tag):
tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'}
self.tekst.inse rt(INSERT, tekst_tag[tag])
Then I get a AttributeError. ..
I seached the net, can come op white a answer.
So I hope You all can!
Bennie, 9 1865
Bennie wrote: def tekst_in(self, tag): tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'} self.tekst.inse rt(INSERT, tekst_tag[tag])
Then I get a AttributeError. .. I seached the net, can come op white a answer.
What specific attribute is mentioned in the AttributeError?
That self has no attribute tekst, or that self.tekst has
no attribute insert?
If the former, you need to arrange your class so that self has
an attribute tekst (e.g. by initializing tekst in __init__).
If the latter: what kind of thing is self.tekst?
Regards,
Martin
Martin v. Löwis wrote: Bennie wrote:
def tekst_in(self, tag): tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'} self.tekst.inse rt(INSERT, tekst_tag[tag])
Then I get a AttributeError. .. I seached the net, can come op white a answer.
What specific attribute is mentioned in the AttributeError? That self has no attribute tekst, or that self.tekst has no attribute insert?
If the former, you need to arrange your class so that self has an attribute tekst (e.g. by initializing tekst in __init__).
If the latter: what kind of thing is self.tekst?
Regards, Martin
self.tekst is a Tkinter.Text() so it has a insert attribute, .insert()
Bennie <be****@rotzjes .nl> writes: Martin v. Löwis wrote: Bennie wrote:
def tekst_in(self, tag): tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'} self.tekst.inse rt(INSERT, tekst_tag[tag])
Then I get a AttributeError. .. I seached the net, can come op white a answer. What specific attribute is mentioned in the AttributeError? That self has no attribute tekst, or that self.tekst has no attribute insert? If the former, you need to arrange your class so that self has an attribute tekst (e.g. by initializing tekst in __init__). If the latter: what kind of thing is self.tekst? Regards, Martin self.tekst is a Tkinter.Text() so it has a insert attribute, .insert()
See, you should have mentioned that before. What you should also
mention is:
1) the _exact_ text of the traceback. Saying "I get an AttributeError"
is not nearly enough: the full message has info that
people-in-the-know know how to interpret. Copy-and-paste it.
2) the smallest (or so) of *working* code that will exhibit the error.
The snippet in your original post doesn't work. Again, copy-and-paste.
Basically, put enough info in your question that we don't have to read
your mind.
Now I'll put my mind-reading cap on...
- Are you sure that tekst_in() is a method, not a function? The
indentation suggests function, while the self parameter suggests method.
- Are you positive self.tekst is a Tkinter.Text()? Throw in some
print statements to check. 'print repr(self)' is a good one.
- tekst_tag[tag] shouldn't be the problem (as suggested by your
original post), as that would raise a KeyError, not an AttributeError.
etc.
(I'll bet once you've done what I've suggested, you'll have found the bug...)
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)phy sics(dot)mcmast er(dot)ca
Hi,
This is a chunck out of my program:
--------------------------------------------------
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.menubar = Menu(root)
self.html = Menu(self.menub ar, tearoff=0)
self.html.add_c ommand(label="p ", command=self.te kst_in('p'))
# self.html.add_c ommand(label="p ", command=self.te kst_a)
self.menubar.ad d_cascade(label ="html", menu=self.html)
root.config(men u=self.menubar)
self.tekst = Text()
self.tekst.pack (fill=BOTH, expand=YES)
def tekst_in(self, tag):
tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'}
self.tekst.inse rt(INSERT, tekst_tag[tag])
# This works
#def tekst_a(self):
# self.tekst.inse rt(INSERT, "<p> </p>")
if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()
--------------------------------------------------
The error is:
-------------------------------
Traceback (most recent call last):
File "test.py", line 30, in ?
app = App(root)
File "test.py", line 10, in __init__
self.html.add_c ommand(label="p ", command=self.te kst_in('p'))
File "test.py", line 21, in tekst_in
self.tekst.inse rt(INSERT, tekst_tag[tag])
AttributeError: App instance has no attribute 'tekst'
------------------------------------------------------
hope this is enough info.
Bennie wrote: Hi,
This is a chunck out of my program: -------------------------------------------------- from Tkinter import *
class App: def __init__(self, master): frame = Frame(master) frame.pack()
self.menubar = Menu(root) self.html = Menu(self.menub ar, tearoff=0) self.html.add_c ommand(label="p ", command=self.te kst_in('p'))
You're using your tekst_in method before setting the attribute self.tekst, so
when the method code is executed, there is actully no attribute named tekst;
hence the Attribute error.
Move the previous line after the self.tekst.pack (...) line and everything should
be fine.
# self.html.add_c ommand(label="p ", command=self.te kst_a) self.menubar.ad d_cascade(label ="html", menu=self.html)
root.config(men u=self.menubar)
self.tekst = Text() self.tekst.pack (fill=BOTH, expand=YES)
def tekst_in(self, tag): tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'} self.tekst.inse rt(INSERT, tekst_tag[tag])
# This works #def tekst_a(self): # self.tekst.inse rt(INSERT, "<p> </p>")
if __name__ == '__main__': root = Tk() app = App(root) root.mainloop()
--------------------------------------------------
The error is: ------------------------------- Traceback (most recent call last): File "test.py", line 30, in ? app = App(root) File "test.py", line 10, in __init__ self.html.add_c ommand(label="p ", command=self.te kst_in('p')) File "test.py", line 21, in tekst_in self.tekst.inse rt(INSERT, tekst_tag[tag]) AttributeError: App instance has no attribute 'tekst' ------------------------------------------------------ hope this is enough info.
HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Eric Brunel wrote: Bennie wrote:
Hi,
This is a chunck out of my program: -------------------------------------------------- from Tkinter import *
class App: def __init__(self, master): frame = Frame(master) frame.pack() self.menubar = Menu(root) self.html = Menu(self.menub ar, tearoff=0) self.html.add_c ommand(label="p ", command=self.te kst_in('p'))
You're using your tekst_in method before setting the attribute self.tekst, so when the method code is executed, there is actully no attribute named tekst; hence the Attribute error.
Move the previous line after the self.tekst.pack (...) line and everything should be fine.
# self.html.add_c ommand(label="p ", command=self.te kst_a) self.menubar.ad d_cascade(label ="html", menu=self.html) root.config(men u=self.menubar) self.tekst = Text() self.tekst.pack (fill=BOTH, expand=YES) def tekst_in(self, tag): tekst_tag={'p': '\t\t<p>\n\n\t\ t</p>\n', 'br': '<br />'} self.tekst.inse rt(INSERT, tekst_tag[tag])
# This works #def tekst_a(self): # self.tekst.inse rt(INSERT, "<p> </p>")
if __name__ == '__main__': root = Tk() app = App(root) root.mainloop()
--------------------------------------------------
The error is: ------------------------------- Traceback (most recent call last): File "test.py", line 30, in ? app = App(root) File "test.py", line 10, in __init__ self.html.add_c ommand(label="p ", command=self.te kst_in('p')) File "test.py", line 21, in tekst_in self.tekst.inse rt(INSERT, tekst_tag[tag]) AttributeError: App instance has no attribute 'tekst' ------------------------------------------------------ hope this is enough info.
HTH
But now he execute te self.tekst_in without user input.
Eric Brunel <er*********@de spammed.com> wrote:
... self.html = Menu(self.menub ar, tearoff=0) self.html.add_c ommand(label="p ", command=self.te kst_in('p')) You're using your tekst_in method before setting the attribute self.tekst, so when the method code is executed, there is actully no attribute named tekst; hence the Attribute error.
Perfectly true.
Move the previous line after the self.tekst.pack (...) line and everything should be fine.
Nope. I guess it won't be, because I suspect the OP doesn't actually
mean to insert a 'p' during the __init__ while adding a command of None.
I guess what he means is that, when that menuentry is selected, then and
only then does a 'p' get inserted. But what he's SAYING is to call the
method right then and there, not set it as a callback as I guess he
means to do.
I think that, to make everything fine, what he needs to do is, rather,
something like:
..., command=lambda: self.tekst_in(' p'))
For the OP (as I think Eric knows this): 'command' must be set to a
CALLABLE, something Tkinter WILL call without arguments later when
needed; you're setting it to the RESULT of a call that you're doing
yourself, right then and there (and that result is None). Prepending a
'lambda:' (an unfortunately murky keyword) makes and binds to command a
no-arguments callable, as needed.
It is, of course, very unlikely that method 'self.tekst_in' only ever
needs to be called with that one argument, 'p', or only ever needs to be
bound that way. If you need to bind callables that will call 'p' with
each of a range of arguments, as would usually be the case, you're
better off forgetting lambda and using closures instead. Say that,
besides 'p', you also want commands 'q', 'r', 's', 't'. Then, do:
self.html = Menu(self.menub ar, tearoff=0)
def make_command(x) :
def callable(): self.tekst_in(x )
return callable
for x in 'pqrst':
self.html.add_c ommand(label=x, command=make_ca llable(x))
Alex
Bennie wrote: self.html.add_c ommand(label="p ", command=self.te kst_in('p'))
Here you are setting the command parameter to the result of the
self.tekst_in() call which is always None. Change that to
self.html.add_c ommand(label="p ", command=self.in sert_para)
and add a method to your App class that takes only the self parameter:
def insert_para(sel f):
self.tekst_in(" p")
That way insert_para() will be invoked when you click the menu command.
Alternately you can use lambda to the same effect:
self.html.add_c ommand(label="p ", command=lambda: self.tekst_in(" p"))
but I think the approach outlined above is cleaner.
Peter
Peter Otten wrote: Bennie wrote:
self.html.add _command(label= "p", command=self.te kst_in('p'))
Here you are setting the command parameter to the result of the self.tekst_in() call which is always None. Change that to
self.html.add_c ommand(label="p ", command=self.in sert_para)
and add a method to your App class that takes only the self parameter:
def insert_para(sel f): self.tekst_in(" p")
That way insert_para() will be invoked when you click the menu command. Alternately you can use lambda to the same effect:
self.html.add_c ommand(label="p ", command=lambda: self.tekst_in(" p"))
but I think the approach outlined above is cleaner.
Peter
Thanks all,
Whit lambda its is working fine.
I want to make a methode that replaces the code:
def p(self):
self.tekst.inse rt(INSERT, "\t\t<p>\n\n\t\ t</p>\n")
def pre(self):
self.tekst.inse rt(INSERT, "\t\t<pre>\n\n\ t\t</pre>\n")
def br(self):
self.tekst.inse rt(INSERT, "<br />")
etc.
Now I have to type les :-)
Bye all! and many thanks ;)
Bennie, This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jason |
last post by:
How does one loop through the contents of a form complicated by dynamic
construction of checkboxes which are assigned a 'model' and 'listingID' to
the NAME field on the fly in this syntax: Hunter_69. Here is what the form
looks like. I have the difficulty of inserting the multiple items selected
by the user the first time he visits and uses the screen and then using an
UPDATE when he visits later.
Model | Original Price | Reduced Price...
|
by: me |
last post by:
I'm also having problems getting the bulk insert to work. I don't know
anything about it except what I've gleened from BOL but I'm not seeming to
get anywhere...Hopefully there is some little (or big) problem with my code
that someone can point out that may save me some time.
TIA
CBL
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
by: Guadala Harry |
last post by:
In an ASCX, I have a Literal control into which I inject a
at runtime.
litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);
This works great as long as the contains just client-side
HTML, CSS, etc.
What I want to do is somehow insert a *server control* into the , then set the server control's properties at runtime.
|
by: Mark Harrison |
last post by:
So I have some data that I want to put into a table. If the
row already exists (as defined by the primary key), I would
like to update the row. Otherwise, I would like to insert
the row.
I've been doing something like
delete from foo where name = 'xx';
insert into foo values('xx',1,2,...);
| |
by: teddysnips |
last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!)
but I can't get it to work because it references ntext fields.
Is there any alternative? I could write it in laborious code in the
application, but I'd rather not!
DDL for table and trigger below.
TIA
|
by: Lorenzino |
last post by:
Hi, I have a problem with bindings in a formview.
I have a formview; in the insert template i've created a wizard control and
inside
it i have an HTML table with some textboxes bound to the sqldatasource of
the
formview.
If i put this textboxes outside the table everything works well, but as soon
as i put them inside the table (in order to organize the layout in the right
way)
they doesn't work. They works only as eval() and not bind()...
|
by: dba123 |
last post by:
I need to perform Asynchronous Inserts using DAAB. So far I have a method
which does an insert but how can I do this Asyncronously so that it does not
affect the load on our public production website? This question is wide open
but make sure you give me some ideas in context with DAAB syntax. Some
thoughts are threading, ATLAS, etc. but I have no clue how to even approach
an Asynchronous Insert or any techniques at this point. Also, I...
|
by: anachronic_individual |
last post by:
Hi all,
Is there a standard library function to insert an array of characters
at a particular point in a text stream without overwriting the existing
content, such that the following data in appropriately moved further
down? From a cursory search of the libc documentation I can't find such
a function. Will I have to write it myself?
Thanks.
|
by: ryushinyama |
last post by:
I had to do a lot of searching to get this one to work and in doing so I saw a lot of different sites where people were looking for this answer so I thought I would put it up.
If you are trying to put data in to a table where you don't want any duplicate data a primary key, unique constraint and all that prevention is the best way to go. However when you try to insert data and it conflicts with an entry you get an error then you have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |