小编lok*_*esh的帖子

如何在python中向3维数组中添加元素

我试图将数据存储在三维数组中,即x[0][0][0]在Python中.如何初始化x并为其添加值?我试过这个:

x=[]
x[0][0][0]=value1 
x[0][0].append(value1)
Run Code Online (Sandbox Code Playgroud)

这两行都超出了范围错误.怎么做?我想它想:x[0][0][0]=value1,x[1][0][0]=value2,x[0][1][0]=value3等.如何在Python实现这一目标?

我期待生成这种数组:

x=[[[11,[111],[112]],[12],[13]],[[21,[211],[212]],[22],[23],[24]],[[31],[32]]]
x[0][0][0] will give 11
x[1][0][0]  21
x[0][0][1] 111
Run Code Online (Sandbox Code Playgroud)

等等

python arrays multidimensional-array

9
推荐指数
2
解决办法
6万
查看次数

如何在tkinter python gui中找到鼠标点击附近的标签

如何识别鼠标点击附近的标签.在这里,我的定义"识别"应该识别非常接近鼠标点击的标签.

from Tkinter import *
root = Tk()
f=Frame(root)
f.grid()
w=Canvas(f)
line1=w.create_line(50,50,150,150, width=5, tags="line1")
line2=w.create_line(100,100,100,350, width=3, tags="line2")
line3=w.create_line(150,150,150,450, width=3, tags="lines")
w.grid(row=0, column=0)
w.bind("<Button-1>", identify)
def identify(event): ## this should identify the tag near to click

u=Frame(f)
u.grid(row=0, column=1)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

谢谢

python user-interface tkinter

2
推荐指数
1
解决办法
3406
查看次数