错误编码初学者的菜鸟程序 [英] error coding noob program for a beginner

查看:61
本文介绍了错误编码初学者的菜鸟程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从过去几天以来我一直在学习python而且我坚持这个项目

基本上我正在制作的是一个程序,其中一个列表的图片名称出现在一边当你点击它们时,它们应该出现在画布的另一侧。

以下我包含了迄今为止的内容。当我运行该程序时,它说list没有属性bind。我很确定它确实如此,但我不能想出这一个,我丢失了源材料,所以我不能参考它。这让我疯了。请帮忙!!!!


-------


#!/ usr / bin / python <来自Tkinter进口的
*来自os import listdir的


def推送():

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。关闭()


li.delete(0,END)

fil = listdir(''friends /'')

对于fil中的项目:

li.insert(END,item)



def按(自我):

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 Frie nd",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 fil中的项目:

li.insert(END,item)


li.bind( < Double-Button-1>,按)



root.mainloop()

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()

推荐答案

输入框在我提交时搞砸了我的代码。缩进在我的程序中,我相信它们是必要的。
the input box screwed up my code when i submitted it. indents ARE in my program where i believe they are necessary.


这就是为什么我们有[code = python]标签,以防止这一点。不幸的是,在您使用适当的缩进发布代码之前,它将更难以帮助您。
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.


Tkinter列表框确实有一个绑定但是您可能错误地实现了列表框。


请参阅发布指南有关如何使用代码标签的说明


您的实现看起来是正确的,因此您必须误解您收到的错误。
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.


这篇关于错误编码初学者的菜鸟程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆