LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2012, 07:01 AM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
[Python] Importing and using tkinter


Hi.

I wrote a script:
Code:
#!/usr/bin/python

from tkinter import *

root = Tk()

header = Entry(root, width=50, bd=1)
text = Text(root, width=50, wrap=WORD)
and it seems to work correctly. Then I changed it to make import other way:
Code:
#!/usr/bin/python

import tkinter

root = tkinter.Tk()

header = tkinter.Entry(root, width=50, bd=1)
text = tkinter.Text(root, width=50, wrap=WORD)
and started to get errors such NameError: name 'WORD' is not defined.
What did I do wrong in second code snippet?
 
Old 09-22-2012, 08:26 AM   #2
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 360

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by Mr. Alex View Post
started to get errors such NameError: name 'WORD' is not defined.
What did I do wrong in second code snippet?
WORD belongs to Tkinter namespace, you have to access it using Tkinter.WORD form. In first example you are importing WORD (together with other names) into your namespace, that's why it's not needed. BTW, it's Tkinter with T capital, I fixed that in your example below:
Code:
#!/usr/bin/python

import Tkinter

root = Tkinter.Tk()

header = Tkinter.Entry(root, width=50, bd=1)
text = Tkinter.Text(root, width=50, wrap=Tkinter.WORD)
 
Old 09-22-2012, 08:29 AM   #3
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 360

Rep: Reputation: 199Reputation: 199
Oops, sorry, you are most likely using Python 3, where Tkinter was renamed to tkinter, I need to be more careful before fixing something that's not broken in the first place.
 
Old 09-22-2012, 08:43 AM   #4
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by audriusk View Post
Oops, sorry, you are most likely using Python 3, where Tkinter was renamed to tkinter, I need to be more careful before fixing something that's not broken in the first place.
Yes, it's Python 3.
Thanks for help, I got it working now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tkinter integration to python 2.3.4 gaddargarson Programming 1 03-09-2005 04:58 AM
Python and Tkinter 1337 Twinkie Fedora 2 08-03-2004 11:35 AM
Python: Tkinter. Chu Programming 0 11-10-2003 01:56 AM
Python and Tkinter Error Gerardoj Programming 1 11-08-2003 09:52 PM
importing trouble....python...regarding Tkinter maseby Programming 0 11-03-2003 01:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration