Python tkinter with ttk calendar

前端 未结 1 1830
闹比i
闹比i 2020-12-19 12:04

I am using this code to create a simple calendar on my Tkinter. When i put a calendar on my main root window, the calendar appear just fine. So, i decided to put another but

相关标签:
1条回答
  • 2020-12-19 12:33

    Author of this widget used one unnecessary action: this widget set minimal size of root window, and he assumed that it is the only window in a program (it isn't bug, it's feature).

    1.In method def __place_widgets(self):

    self._calendar = ttk.Treeview(show='', selectmode='none', height=7)
    

    should be:

    self._calendar = ttk.Treeview(self, show='', selectmode='none', height=7)
    

    2.In constructor remove line:

    self._calendar.bind('<Map>', self.__minsize)
    

    3.Delete __minsize method
    4.If you want to set minimal size for root2 use this code:

    def myfunction():
        root2=Tkinter.Toplevel(root)
        ttkcal = Calendar(root2,firstweekday=calendar.SUNDAY)
        ttkcal.pack(expand=1, fill='both')
        root2.update()
        root2.minsize(root2.winfo_reqwidth(), root2.winfo_reqheight())
    
    0 讨论(0)
提交回复
热议问题