我正在嘗試為我的日歷創建一個單擊功能。
class MainWindow():
def __init__(self, app) :
#---------------------------------Initialisation de la page principale------------------------------------
self.app = app
self.app.title("Page Principale")
# Center main window
#----------------------------------------------------------------
app_width = 800
app_height = 600
screnn_width = app.winfo_screenwidth()
screnn_heigth = app.winfo_screenheight()
x = (screnn_width / 2) - (app_width / 2)
y = (screnn_heigth / 2) - (app_height / 2)
self.app.geometry(f'{app_width}x{app_height} {int(x)} {int(y)}')
#----------------------------------------------------------------
self.app.config(background="azure")
self.app.resizable(0,0)
self.app.focus_force()
today = datetime.date.today()
self.cal = Calendar(app, selectmode="day", year=today.year, month=today.month, day=today.day, date_pattern="mm/dd/yyyy")
self.cal.pack(ipady=20, fill="both", expand=True)
self.cal.bind('<Double-1>', self.double_click)
這是我的 double_click 函式:
def double_click(self, event):
print("event double click effectuer")
問題是我的功能沒有執行我希望當我在日歷中時,當我雙擊時,我會出現訊息。但僅在日歷中,不在應用程式的其余部分中。目標是針對特定的一天,當用戶雙擊時,將打開一個模式視窗,其中包含他單擊 Thx 以尋求幫助的當天的許多資訊!
uj5u.com熱心網友回復:
該Calendar小部件是一個由標簽填充/覆寫的框架,這就是系結不起作用的原因,因為這些標簽而不是日歷小部件消耗了雙擊事件。
查看代碼tkcaender.Calendar,實體變數_calendar(2D 串列)用于存盤這些標簽。所以你可以系結<Double-1>這些標簽:
for row in self.cal._calendar:
for lbl in row:
lbl.bind('<Double-1>', self.double_click)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/437491.html
標籤:Python 用户界面 tkinter tkcalendar
