ive been learning python since the last couple days and am stuck on this "project"
basically what i am making is a program where a list of picture names appear in a list on one side and when you click them they should appear on the other side in a canvas.
below i included what i have so far. when i run the program it says that "list" does not have attribute "bind". im pretty sure it does, but i cant figure this one out and i lost the source material so i cannot reference it. this is driving me nuts. please help!!!!
-------
#!/usr/bin/python
from Tkinter import *
from os import listdir
def Pushed():
friend_name = ent.get()
friend_info = tex.get(0.0,END)
friend_name = "friends/" + friend_name
fil = file(friend_name,'w')
fil.write(friend_info)
fil.close()
li.delete(0,END)
fil = listdir('friends/')
for item in fil:
li.insert(END,item)
def Press(self):
tex.delete(0.0,END)
ent.delete(0,END)
selec = li.curselection()
str = li.get(selec[0])
ent.insert(END,str)
str = 'friends/' + str
fin = file(str,'r')
outp = fin.read()
fin.close()
tex.insert(END, outp)
root = Tk()
root.geometry('500x350+270+50')
lab = Label(root,text = "Friend directory")
name = Label(root, text = "name")
butto = Button(root, text = "New Friend", command = Pushed)
ent = Entry(root, bg = 'white', width = 40)
li = Listbox(root, bg = 'white', height = 13)
tex = Text(root, bg = 'white', font=("Helvatica",15), width = 30, height = 15)
lab.grid(row = 0, columnspan = 3)
name.grid(row = 1, column = 0)
ent.grid(row = 1, column = 1)
li.grid(rowspan = 2, column = 0 )
tex.grid(row = 2, column = 1)
butto.grid(row = 3, column = 1)
fil = listdir('friends/')
for item in fil:
li.insert(END,item)
li.bind("<Double-Button-1>",Press)
root.mainloop()
10 1607
the input box screwed up my code when i submitted it. indents ARE in my program where i believe they are necessary.
This is why we have the [code=python] tags, to prevent exactly that. Unfortunately, until you post your code with proper indentations, it'll be much harder to help you.
The Tkinter listbox does have a bind but perhaps you have implemented the list box incorrectly.
Refer to the posting guidelines for an explanation of how to use the code tags
Your implementation looks correct so you must be mistaken about the error that you are receiving.
you need to format this in the "CODE" selection so that we can copy the code right out of your post. Otherwise, no one will want to help you.
sorry guys, its my first time using this forum. here is my code properly displayed, thanks! -
from Tkinter import *
-
from os import *
-
from string import *
-
-
def Press():
-
selec=lis.curselection()
-
print selec
-
str = lis.get(selec[0])
-
print str
-
-
tem = can.create_image(x,y, image = pic)
-
-
-
root = Tk()
-
root.geometry('700x600+270+50')
-
-
lab = Label(root, text = 'Name of the picture', font=('Times', 12))
-
can = Canvas(root, width ='500', height = '400', bg ='white')
-
lis = Listbox(root, height=20)
-
-
pic = listdir('pictures/')
-
-
for item in pic:
-
lis.insert(0,item)
-
-
pic.bind("<Double-Button-1>",Press)
-
-
-
-
lis.focus()
-
lab.pack()
-
can.pack()
-
lis.pack()
-
-
root.mainloop()
-
sorry guys, its my first time using this forum. here is my code properly displayed, thanks! -
from Tkinter import *
-
from os import *
-
from string import *
-
-
def Press():
-
selec=lis.curselection()
-
print selec
-
str = lis.get(selec[0])
-
print str
-
-
tem = can.create_image(x,y, image = pic)
-
-
-
root = Tk()
-
root.geometry('700x600+270+50')
-
-
lab = Label(root, text = 'Name of the picture', font=('Times', 12))
-
can = Canvas(root, width ='500', height = '400', bg ='white')
-
lis = Listbox(root, height=20)
-
-
pic = listdir('pictures/')
-
-
for item in pic:
-
lis.insert(0,item)
-
-
pic.bind("<Double-Button-1>",Press)
-
-
-
-
lis.focus()
-
lab.pack()
-
can.pack()
-
lis.pack()
-
-
root.mainloop()
-
It's ok, I'm pretty new to this too, and actually I made the same mistake you made the first time I posted. Unfortunately, I can't help you with your problem... but be patient, there are many intelligent people in this community that can
help. Good Luck with your coding!
I was able to resolve the error that u mentioned but was not really not successful in getting the images displayed, try this and see if you are able to get going.
The problem was here
pic.bind("<Double-Button-1>",Press)
pic is a list u cannot bind an action to a list instead try this - from Tkinter import *
-
from os import *
-
from string import *
-
-
def Press(event):
-
selec=lis.curselection()
-
selected = lis.get(selec[0])
-
photo1 = PhotoImage(file=selected)
-
can.create_image(200, 100, image=photo1)
-
-
root = Tk()
-
root.geometry('700x600+270+50')
-
-
lab = Label(root, text = 'Name of the picture', font=('Times', 12))
-
can = Canvas(width =300, height = 300, bg ='white')
-
lis = Listbox(root, height=20,selectmode=EXTENDED)
-
-
pic = listdir('pictures/')
-
for item in pic:
-
lis.insert(0,item)
-
-
lis.bind("<Double-Button-1>", Press)
-
-
lis.focus()
-
lab.pack()
-
can.pack()
-
lis.pack()
-
root.mainloop()
ok so this time i have everything displaying correctly but the program still doesnt work. i have the new error message and the new code posted below -
-
from Tkinter import *
-
from os import *
-
from string import *
-
-
#def Press(self):
-
# selec=lis.curselection()
-
# print selec
-
# str = lis.get(selec[0])
-
#print str
-
#tem = can.create_image(image = pic)
-
-
-
def Press(self):
-
selec=lis.curselection()
-
selected = lis.get(selec[0])
-
photo1 = PhotoImage(file=selected)
-
can.create_image(200, 100, image=photo1)
-
-
-
root = Tk()
-
root.geometry('700x600+270+50')
-
-
lab = Label(root, text = 'Name of the picture', font=('Times', 12))
-
can = Canvas(root, width ='500', height = '400', bg ='white')
-
lis = Listbox(root, height=20)
-
-
pic = listdir('pictures/')
-
-
for item in pic:
-
lis.insert(0,item)
-
-
lis.bind("<Double-Button-1>",Press)
-
-
-
-
lis.focus()
-
lab.pack()
-
can.pack()
-
lis.pack()
-
-
root.mainloop()
-
-
(())__ this is the error message below:
IDLE 1.2.2 ==== No Subprocess ====
>>>
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
File "C:\Documents and Settings\Administrator\Desktop\first python lessons\lecture 15.pyw", line 16, in Press
photo1 = PhotoImage(file=selected)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 3270, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python25\lib\lib-tk\Tkinter.py", line 3226, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "th_img322.gif": no such file or directory
This error is telling you that PYthon cannot locate the image file that you have specified. When you are working with opening text files, image files, etc. it is always a good idea to use absolute paths instead of relative to avoid things like this happening. So instead of Python looking for mypic.jpg it's looking for C:\Doc and Settings\Me\My Pictures\mypic.jpg....
So on this line:
selected = lis.get(selec[0])
You could say
selected = os.path.join( my_images_path, lis.get( selec[0] ) )
** NOTE: my_images_path is the path where your images are stored, so fill it in with the proper value
That way Python will know exactly where to go for the image
here is the most recent version of the code. i dont get any error messages anymore but the pictures do not display on the canvas. tell me what you think, any advice? whats wrong with it? -
#! usr/bin/python
-
-
from Tkinter import *
-
from os import *
-
from string import *
-
-
-
def Press(event):
-
selec=lis.curselection()
-
selected = lis.get(selec[0])
-
photo1 = PhotoImage('file=selected')
-
can.create_image(200, 100, image=photo1)
-
-
-
root = Tk()
-
root.geometry('700x600+270+50')
-
-
lab = Label(root, text = 'Name of the picture', font=('Times', 12))
-
can = Canvas(root, width ='500', height = '400', bg ='white')
-
lis = Listbox(root, height=20)
-
-
pic = listdir('pictures/')
-
-
for item in pic:
-
lis.insert(0,"pictures/"+item)
-
-
lis.bind("<Double-Button-1>",Press)
-
-
-
-
lis.focus()
-
lab.pack()
-
can.pack()
-
lis.pack()
-
-
root.mainloop()
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: administrata |
last post by:
I'm programming Car Salesman Program.
It's been "3 days" learning python...
But, i got problem
Write a Car Salesman program where the user enters the base price of a
car. The program should...
|
by: We need more power captain |
last post by:
Hi,
I know less than a noob, I've been asked to do some compiles in VC++ 6
without knowing too much at all. (I'm a COBOL program normally so
this is all too much for me)
I open VC++6, open...
|
by: Matt |
last post by:
Ok, sorry for posting so much, but I just have alot of questions. Ok,
so It says to make a program to count blanks, tabs, and newlines.
So I made one:
#include <stdio.h>
/* Count tabs,...
|
by: Simon Hengel |
last post by:
Hello,
we are hosting a python coding contest an we even managed to provide a
price for the winner...
http://pycontest.net/
The contest is coincidentally held during the 22c3 and we will be...
|
by: Mike Polinske |
last post by:
I am new to the C programming language but have been programming in
Cobol for over 10 years. When I compile the following code, it
compiles clean but I get an application error both under Windows...
|
by: calmar |
last post by:
Hi all,
since I'm just a 'handicraft'/beginner or so,
could anybody provide me with some (rough) hints, about how to enhance the code
here:
http://calmar.ws/tmp/cal.html
Cheers and...
|
by: Prasad |
last post by:
HI,
I am a beginner in VC++..
I am trying to write a Win32 console application in visual studio..
I am using following header files..
#include <STRING>
using namespace std;
#include...
|
by: Omar |
last post by:
Hi all...this is a good group so I'm sure you'll tolerate some more
noobish questions...
1) I'm also learning to program flash movies while I learn to do
python. How can one implement flash...
|
by: coffeetime |
last post by:
Hi,
I just decided to learn java, so I'm quite a noob.
I use the book learning java third edition.
have JDK 1.6
program in notepad.
I have made the simple HelloJava example, and now i wanted to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
| |