user7391836
user7391836

Reputation: 118

How to change default time of tkTimePicker analog clock

I am using the Analog Picker from tkTimePicker. The default time (the time that it shows initially) is 12:59 AM. I want to be able to change the default time to what the user saved it previously.

My current code for showing the time picker is:

from tkinter import *
from tktimepicker import AnalogPicker, AnalogThemes, constants
def editTime():
    editTimeWindow = Toplevel(window)
    time_picker = AnalogPicker(editTimeWindow, type=constants.HOURS12)
    time_picker.pack(expand=True, fill="both")
    theme = AnalogThemes(time_picker)
    theme.setNavyBlue()
    editTimeWindow.mainloop()

editTime()

image from https://github.com/PaulleDemon/tkTimePicker/blob/master/Readme.md

Is there a way to change the default time?

Upvotes: 0

Views: 843

Answers (1)

user7391836
user7391836

Reputation: 118

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()

Upvotes: 1

Related Questions