第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 canvas.delete("all") 之后在畫布中重用框架小部件不起作用

在 canvas.delete("all") 之后在畫布中重用框架小部件不起作用

呼啦一陣風(fēng) 2023-07-05 16:15:32
我在畫布中創(chuàng)建了一個框架,通過單擊鼠標(biāo)在其中放置復(fù)選按鈕。選擇另一個單選按鈕,我運行命令 canvas.delete("all") 來清除畫布(以及帶有復(fù)選按鈕的框架),然后再次創(chuàng)建框架以繼續(xù)放置復(fù)選按鈕??蚣芤褎?chuàng)建,但我無法再放置檢查按鈕(我也沒有收到錯誤消息)。有人知道為什么嗎?from tkinter import *root = Tk()top_canvas = Canvas(root,width=676,height=768, bg='light blue')top_canvas.pack()frame = Frame(top_canvas, bg='light grey')main_frame = top_canvas.create_window(500, 780, height = 1600, width = 600, window = frame)def place_checkbutton_in_canvas(e):  # order to insert the checkbutton    xx = e.x    yy = e.y    buttons = Checkbutton(frame)    buttons.place(x=xx, y=yy)def place_checkbutton():  #to run when checkbutton is selected. Now the checkbutton will be placed where mouse clicked if choose_line is selected    frame.bind('<Button-1>', place_checkbutton_in_canvas)def clear_canvas():    top_canvas.delete("all")    frame = Frame(top_canvas, bg='magenta')    main_frame = top_canvas.create_window(500, 780, height=1600, width=600, window=frame)chosen_option = IntVar()choose_checkbutton = Radiobutton(root, text = "place checkbutton", variable=chosen_option, value = 1, command = place_checkbutton)choose_checkbutton.place(x=10, y=10)clear_button = Radiobutton(root, text = "clear everything", variable=chosen_option, value = 2, command = clear_canvas)clear_button.place(x=10, y=100)root.mainloop()
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻1804條經(jīng)驗 獲得超2個贊

無需刪除畫布上的所有項目。您可以使用列表來保存所有檢查按鈕,并使用.destroy()“刪除”它們:


from tkinter import *


root = Tk()

top_canvas = Canvas(root,width=676,height=768, bg='light blue')

top_canvas.pack()

root.checkbutton_list = [] # initial a list


frame = Frame(top_canvas, bg='light grey')

main_frame = top_canvas.create_window(500, 780, height = 1600, width = 600, window = frame)


def place_checkbutton_in_canvas(e):  # order to insert the checkbutton

    xx = e.x

    yy = e.y

    buttons = Checkbutton(frame)

    buttons.place(x=xx, y=yy)

    root.checkbutton_list.append(buttons) # append the checkbutton to the list


def place_checkbutton():  #to run when checkbutton is selected. Now the checkbutton will be placed where mouse clicked if choose_line is selected

    frame.bind('<Button-1>', place_checkbutton_in_canvas)


def clear_canvas():

    for i in root.checkbutton_list:

        i.destroy() # destroy all the checkbuttons in the list

    root.checkbutton_list = [] # init it again


chosen_option = IntVar()

choose_checkbutton = Radiobutton(root, text = "place checkbutton", variable=chosen_option, value = 1, command = place_checkbutton)

choose_checkbutton.place(x=10, y=10)

clear_button = Radiobutton(root, text = "clear everything", variable=chosen_option, value = 2, command = clear_canvas)

clear_button.place(x=10, y=100)


root.mainloop()

如果你真的想將它與 一起使用.delete(ALL)。你需要更改 checkbutton 的父容器。我用它root.frame來覆蓋前一幀。例如:


from tkinter import *


root = Tk()

top_canvas = Canvas(root,width=676,height=768, bg='light blue')

top_canvas.pack()


root.frame = Frame(top_canvas, bg='light grey')

main_frame = top_canvas.create_window(500, 780, height = 1600, width = 600, window = root.frame)


def place_checkbutton_in_canvas(e):  # order to insert the checkbutton

    xx = e.x

    yy = e.y

    buttons = Checkbutton(root.frame)

    buttons.place(x=xx, y=yy)


def place_checkbutton():  #to run when checkbutton is selected. Now the checkbutton will be placed where mouse clicked if choose_line is selected

    root.frame.bind('<Button-1>', place_checkbutton_in_canvas)


def clear_canvas():

    top_canvas.delete("all")

    root.frame = Frame(top_canvas, bg='magenta')

    main_frame = top_canvas.create_window(500, 780, height=1600, width=600, window=root.frame)


chosen_option = IntVar()

choose_checkbutton = Radiobutton(root, text = "place checkbutton", variable=chosen_option, value = 1, command = place_checkbutton)

choose_checkbutton.place(x=10, y=10)

clear_button = Radiobutton(root, text = "clear everything", variable=chosen_option, value = 2, command = clear_canvas)

clear_button.place(x=10, y=100)


root.mainloop()


查看完整回答
反對 回復(fù) 2023-07-05
  • 1 回答
  • 0 關(guān)注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號