亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如何刪除 tkinter 中按鈕之間的空間?

如何刪除 tkinter 中按鈕之間的空間?

GCT1015 2023-12-20 16:11:06
在我的應用程序中,我看到彩色按鈕之間有很多我實際上不想要的空間,我該如何刪除它們?我嘗試使用button.pack(pady=0)按鈕但沒有任何效果我已在此處添加了我的代碼,并嘗試僅放置代碼的相關部分我添加了畫布,這樣我就可以添加滾動條。我使用按鈕是因為我想添加一個方法來顯示可以編輯/刪除任務的頁面。class TodoFrame(Frame):    def __init__(self, parent, controller):        Frame.__init__(self, parent)        self.canvas = Canvas(self)        self.scrollbar = Scrollbar(self, orient="vertical", command=self.canvas.yview)        task_frame = Frame(self.canvas, height=self.winfo_height()-100)        task_frame.pack(fill="x", expand=True)        self.canvas.create_window(0, 0, anchor='center', window=task_frame, width=self.winfo_width(), height=self.winfo_height()-100)        priority_colors = ("#00CED1", "#00FA9A", "#FF6347", "#B0C4DE")  # colors for buttons        # the db.fetch_incomplete_tasks() fetches tasks from mysql database        # and returns a list of tuples containing title, description, priority and completion status of the task        self.incomplete_tasks = sorted(db.fetch_incomplete_tasks(), key=lambda x: x[2])  # sorting list by priority        if self.incomplete_tasks:            incomplete_task_label = Label(task_frame, text="Incomplete Tasks", font=('calibri', 16))            incomplete_task_label.pack(padx=(50, 0), anchor="center")                        for task in self.incomplete_tasks:                title, description, priority, status = task                task_btn = Button(task_frame, text=title, bg=priority_colors[priority-1], bd=0, width=25, wraplength=400, justify="left", pady=5)                task_btn.pack(expand=True, padx=(50,0))
查看完整描述

1 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

所以問題是我在這一行設置了畫布的高度 self.canvas.create_window(0, 0, anchor='center', window=task_frame, width=self.winfo_width(), height=self.winfo_height()-100)

這導致了額外空間的形成,而按鈕之間的空間就是為了填補這個間隙



查看完整回答
反對 回復 2023-12-20
  • 1 回答
  • 0 關注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號