有没有办法在python中的2个小部件上检测FocusOut事件

时间:2019-05-20 08:49:40

标签: python tkinter

我想要的是自由地选择日期,只要我在dateEntry小部件上即可(即使我单击向下箭头也不会销毁),如果我单击某些,则销毁最后一个(dateEntry)还有什么地方。

问题在于tkcalender是由多个小部件组成的,这就是为什么focusOut事件仅在其中之一上设置的原因。

from tkinter import *
from tkcalendar import DateEntry

def ok(e):
    print(cal.get_date())


root = Tk()
cal = DateEntry(root, year=2010)
cal.pack(padx=10, pady=10)
cal.bind('<FocusOut>', lambda e: cal.destroy())
cal.bind('<Return>', ok)  # validate with Enter
cal.focus_set()

root.mainloop()

如果运行代码,然后单击DateEntry的箭头,则该行将被销毁,我希望该行一直保留在那里,直到您单击窗口中要销毁的其他位置。

1 个答案:

答案 0 :(得分:1)

如果我对您的理解正确,那么您希望单击打开日历时不要破坏library(dplyr) library(purrr) df %>% group_by(Res) %>% summarise_if(is.numeric, sum, na.rm = TRUE) %>% arrange(Res= factor(Res, levels=c('Urban','Rural'))) %>% mutate(City = "State") %>% bind_rows(df) %>% mutate(City=factor(City, levels = c('State','A','B','C'))) %>% split(.$City) %>% map_df(., ~bind_rows(summarise_if(.x,is.numeric, sum) %>% mutate(City='Total', Res=''), .x %>% mutate_if(is.factor, as.character)) %>% select(City, Res, Pop, Pop1)) # A tibble: 12 x 4 City Res Pop Pop1 <chr> <chr> <int> <int> 1 Total "" 3001765 2972 2 State Urban 1501974 1483 3 State Rural 1499791 1489 4 Total "" 1000915 987 5 A Urban 500414 493 6 A Rural 500501 494 7 Total "" 999938 1009 8 B Urban 499922 497 9 B Rural 500016 512 10 Total "" 1000912 976 11 C Urban 501638 493 12 C Rural 499274 483 。可以通过检查当前焦点和DateEntry(如果当前焦点是pass对象)来实现。

Calendar

尝试按Tab键更改焦点并查看。