Home > Mobile >  How to change default time of tkTimePicker analog clock
How to change default time of tkTimePicker analog clock

Time:04-29

I am using the Analog Picker from image from https://github.com/PaulleDemon/tkTimePicker/blob/master/Readme.md

Is there a way to change the default time?

CodePudding user response:

I asked this question on github, and PaulleDemon, the creator, updated the project to allow this.

Minimum version: 2.0.2

You can use setHours(10) to set the hour to 10 and setMinutes(50) to set the minutes to 50. AnalogPicker takes period as a parameter which is set to AM by default. You can change this to PM using AnalogPicker(parent, period=constants.PM)

Code example:

from tkinter import *
from tktimepicker import AnalogPicker, AnalogThemes, constants



def pick_time():

    toplevel = Toplevel(root)
    
    picker = AnalogPicker(toplevel, period=constants.PM) #take out 'period=constants.PM' to change to AM
    picker.setHours(10) #set the hour to 10
    picker.setMinutes(45) #set the minutes to 45

    picker.pack(fill="both", expand=True)
    theme = AnalogThemes(picker)
    theme.setNavyBlue()


root = Tk()

btn = Button(text="pick time", command=pick_time)
btn.pack()

root.mainloop()
  • Related