편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.07.07

    파이썬 tkinter 삭제 버튼을 누르면 체크된 라벨 프레임을 삭제하고 싶은데


    number = tk.StringVar()
    number_chosen = ttk.Combobox(choice_object, width= 12, textvariable=number)
    number_chosen['values'] = [1,2,3]
    number_chosen.place(x=50, y=410, width=50, height= 30)
    
    def add():
        global chbox_1,label_1
        for i in range(int(number_chosen.get())):
            label_1 = tk.LabelFrame(choice_object)
            label_1.pack(pady=30)
            chbox_1 = tk.IntVar()
            check1 = tk.Checkbutton(label_1, variable=chbox_1, onvalue= 1, offvalue= 0)
            check1.pack(side=LEFT)
            label_2 = tk.Label(label_1, text= "물체 " + str(i+1))
            label_2.pack(side=LEFT, padx= 5)
    
    
    
    
    btn_add = tk.Button(choice_object, text= "추가", command= add)
    btn_add.place(x=150, y=410, width=50, height= 30)
    
    btn_del = tk.Button(choice_object, text= "삭제", command=lambda: label_1.destroy())
    btn_del.place(x=150, y=450, width=50, height= 30)
    

    삭제 버튼을 누르면 체크된 라벨 프레임을 삭제하고 싶은데 지금 이대로 하면 맨마지막 것만 삭제되는데 방법이 있을까요?

  • 프로필 ᅟᅟᅟᅟ님의 편집
    날짜2021.07.04

    파이썬 질문드립니다.


    number = tk.StringVar()
    number_chosen = ttk.Combobox(choice_object, width= 12, textvariable=number)
    number_chosen['values'] = [1,2,3]
    number_chosen.place(x=50, y=410, width=50, height= 30)
    
    def add():
        global chbox_1,label_1
        for i in range(int(number_chosen.get())):
            label_1 = tk.LabelFrame(choice_object)
            label_1.pack(pady=30)
            chbox_1 = tk.IntVar()
            check1 = tk.Checkbutton(label_1, variable=chbox_1, onvalue= 1, offvalue= 0)
            check1.pack(side=LEFT)
            label_2 = tk.Label(label_1, text= "물체 " + str(i+1))
            label_2.pack(side=LEFT, padx= 5)
    
    
    
    
    btn_add = tk.Button(choice_object, text= "추가", command= add)
    btn_add.place(x=150, y=410, width=50, height= 30)
    
    btn_del = tk.Button(choice_object, text= "삭제", command=lambda: label_1.destroy())
    btn_del.place(x=150, y=450, width=50, height= 30)
    

    삭제 버튼을 누르면 체크된 라벨 프레임을 삭제하고 싶은데 지금 이대로 하면 맨마지막 것만 삭제되는데 방법이 있을까요?

  • 프로필 강태영님의 편집
    날짜2021.07.04

    파이썬 질문드립니다.


    number = tk.StringVar() number_chosen = ttk.Combobox(choice_object, width= 12, textvariable=number) number_chosen['values'] = [1,2,3] number_chosen.place(x=50, y=410, width=50, height= 30)

    def add(): global chbox_1,label_1 for i in range(int(number_chosen.get())): label_1 = tk.LabelFrame(choice_object) label_1.pack(pady=30) chbox_1 = tk.IntVar() check1 = tk.Checkbutton(label_1, variable=chbox_1, onvalue= 1, offvalue= 0) check1.pack(side=LEFT) label_2 = tk.Label(label_1, text= "물체 " + str(i+1)) label_2.pack(side=LEFT, padx= 5)

    btn_add = tk.Button(choice_object, text= "추가", command= add) btn_add.place(x=150, y=410, width=50, height= 30)

    btn_del = tk.Button(choice_object, text= "삭제", command=lambda: label_1.destroy()) btn_del.place(x=150, y=450, width=50, height= 30)

    삭제 버튼을 누르면 체크된 라벨 프레임을 삭제하고 싶은데 지금 이대로 하면 맨마지막 것만 삭제되는데 방법이 있을까요?