473,800 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Principiante in cerca di spiegazione!

Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Fra me):

# metodo che scrive un messaggio a video
def scrivi_messaggi o(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messag gio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()

# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack( {"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_mes saggio
self.butt_mess. pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_ mess = Button(f)
self.butt_canc_ mess["text"] = "Cancella",
self.butt_canc_ mess["command"] = self.cancella_m essaggio
self.butt_canc_ mess.pack({"sid e": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack( {"side": "left"})
# corpo principale del programma
finestra = Tk()
app = Application(fin estra)
finestra.mainlo op()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Fra me):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto
Jul 18 '05 #1
3 1488
Augusto wrote:
Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Fra me):

# metodo che scrive un messaggio a video
def scrivi_messaggi o(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messag gio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()
You may be mixing tabs and spaces. Try to use *only* spaces.
Every thing from here...
# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack( {"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_mes saggio
self.butt_mess. pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_ mess = Button(f)
self.butt_canc_ mess["text"] = "Cancella",
self.butt_canc_ mess["command"] = self.cancella_m essaggio
self.butt_canc_ mess.pack({"sid e": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack( {"side": "left"})
.... to here must be indented to the same level as the two first lines in
the body of the __init__() method
# corpo principale del programma
finestra = Tk()
app = Application(fin estra)
finestra.mainlo op()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Fra me):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined
f is only known inside the body of __init__()

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto


Remember: whitespace *is* significant in Python.

Peter

PS: Try to post in english, nobody will care for occasional mistakes.

Jul 18 '05 #2
On Wednesday 11 February 2004 4:43 pm, Augusto wrote:
Ciao a tutti,
premetto a tutti che stò imparando proprio adesso a studiare python ed
ho il seguente problema ... questo script copiato pari pari da un
tutorial mi ridà un'errore che non capisco.. questo è il codice:

from Tkinter import * # importo il modulo

# costruisco una mia classe che gestisce la finestra
class Application(Fra me):

# metodo che scrive un messaggio a video
def scrivi_messaggi o(self):
self.mess["text"] = "Ciao a tutti!",

# metodo che pulisce il messaggio a video
def cancella_messag gio(self):
self.mess["text"] = "",

# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()

# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack( {"side": "left"})

# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_mes saggio
self.butt_mess. pack({"side": "left"})

# crea il bottone che permette di pulire il messaggio
self.butt_canc_ mess = Button(f)
self.butt_canc_ mess["text"] = "Cancella",
self.butt_canc_ mess["command"] = self.cancella_m essaggio
self.butt_canc_ mess.pack({"sid e": "left"})

# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack( {"side": "left"})
# corpo principale del programma
finestra = Tk()
app = Application(fin estra)
finestra.mainlo op()

e mi ritorna un'errore come:

Traceback (most recent call last):
File "C:/Python23/tests/tkinter.py", line 4, in -toplevel-
class Application(Fra me):
File "C:/Python23/tests/tkinter.py", line 20, in Application
self.esci = Button(f)
NameError: name 'f' is not defined

?? Eppure la var f è definita nell' _INIT_

qualcuno mi sà spiegare perchè?

Grazie in anticipo!

Augusto


f is indeed defined in __init__ and is therefore local to __init__. The name
is not available outside that method. I think that your problem may be that
the code following "f.pack()" to the end of the class definition is meant
also to be part of the __init__ function. Try indenting it all to be level
with "f.pack()".

James
--
James Henderson, Logical Progression Ltd.
http://www.logicalprogression.net/
http://sourceforge.net/projects/mailmanager/
Jul 18 '05 #3
All right.. Thanks! Now it's ok..

Python rulez! bye!
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
5850
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no luck. > For example, google has a button <input type=submit value="Google > Search" name=btnG> how would i make a script to press that button? I have a similar target: web automation, which
34
6882
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: 1) get whole string of input line 2) preset table of strings matching <command> 3) preset table of function calls
0
244
by: sara | last post by:
Hi, I have a little problem. This is the code one of my page. My problem is that the function "leggi1" is not executed. Where do I make a mistake? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Homepage.aspx.vb" Inherits="Homepage" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %> <%@ Import Namespace="System.Data.SqlClient" %>
0
942
by: sara | last post by:
Hi, this is the code of a (2005) asp page. I've a problem during the execution. When I click on "Leggi" button the javascript function "leggi1" is not done! Why? Someone can I helm me, please! <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Homepage.aspx.vb" Inherits="Homepage" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OleDb" %>
19
2084
by: ash | last post by:
hi friends, i have some questions whch is in my last year question papers.i need some help to get logic of these questions. 1) write a C function, that takes two strings as arguments and returns a pointer to the first occurrence of 1st string in 2nd string or NULL if it is not present. -- i tried to solve it but it seems that i am not understanding this question at all.i am taking this question as:
1
1178
by: seba | last post by:
Ciao a tutti, vorrei sviluppare in C++ sotto Fedora Core 5. Ho dei problemi con ECLIPSE, quindi chiedo se qualcuno puo' consigliarmi qualche buon tool di sviluppo. CIAO!
0
240
by: molcaleviATyahoogroupsDOTcom | last post by:
B " H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! ! e' SAUDITA - Bin Laden la cosi' detta '' mafia ebraica CFR globalmafia ILLUMINATI '' . Pensioniamola con TRIVOLUZIONE ARTSENU + FUSIONE FREDDA .
1
6357
by: diaboliko80 | last post by:
Salve a tutti. Ho un problema con IE7. Ho implementato una pagina .asp che tramite tecnologia AJAX mi crea una serie di select nidificate (il classico esempio delle Regioni-Province --scelgo dalla prima select una regione d'Italia e popolo dinamicamente la seconda select con le province corrispondenti). Tutto questo funziona perfettamente con FireFox. Mi sono accorto poi che su Internet Explorer 7 invece non funziona per
0
1442
by: molcaleviATyahoogroupsDOTcom | last post by:
KO mafia CFR ILLUMINATI ! Global Democracy TRIVOLUZIONE ARTSENU COLD FUSION W post OPEC ! B '' H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! !
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
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...
1
7580
isladogs
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...
0
5471
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...
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.