我正在学习python和tkinter,我尝试从类B中的类A中删除一个对象,但是什么也没有发生,当我单击butB时也没有错误消息。感谢您的帮助
var str = '01.jpg,02.jpg,03.jpg';
var arr = str.split(',');
var values = arr.map(function(image) {
var img = document.createElement('img')
img.src = "/imgt" + image;
img.alt = "img";
return img;
})
console.log(values)
答案 0 :(得分:0)
create_line
给出了您必须保留的ID
self.id = self.can.create_line(10, 10, 90, 90, fill='red', width=5)
并使用它从画布中删除行。
def butB(self):
self.can.delete(self.x.id)
您还可以使用此ID来移动行或更改其配置(颜色等)
from tkinter import *
class FaceDom(object):
def __init__(self, can):
self.can = can
self.id = self.can.create_line(10, 10, 90, 90, fill='red', width=5)
class Projet(Frame):
def __init__(self, larg, haut):
Frame.__init__(self)
self.larg, self.haut = larg, haut
self.can = Canvas(self, bg='dark green', width =larg, height =haut)
self.can.pack()
bList = [("ligne", self.butA),("Delete",self.butB)]
for b in bList:
Button(self, text =b[0], command =b[1]).pack()
self.pack()
def butA(self):
self.x = FaceDom(self.can)
print(self.x)
def butB(self):
self.can.delete(self.x.id)
Projet(100, 100).mainloop()