[Tutor] Tkinter Calendar to receive user entry.
Peter Otten
__peter__ at web.de
Tue Feb 7 14:40:18 EST 2017
Alan Gauld via Tutor wrote:
> On 07/02/17 10:18, Peter Otten wrote:
>
>> $ cat demo.py
>> #!/usr/bin/env python
>> import calendar
>> import ttk
>> import Tkinter
>> from ttkcalendar import Calendar
>
> Doesn't work for me in either Python 3.6.0 or in Python 2.7.6
>
> Which version of 2.7 are you using?
The distribution's Python 2.7.6 on Linux Mint 17. After fixing the import
statements...
$ head ttkcalendar.py
"""
Simple calendar using ttk Treeview together with calendar and datetime
classes.
"""
import calendar
try:
import Tkinter
import tkFont
import ttk
except ImportError: # py3k
import tkinter as Tkinter
import tkinter.font as tkFont
from tkinter import ttk
def get_calendar(locale, fwday):
# instantiate proper calendar class
if locale is None:
return calendar.TextCalendar(fwday)
else:
$ cat demo.py
#!/usr/bin/env python
import calendar
try:
import tkinter as tk
from tkinter import ttk
except ImportError:
import ttk
import Tkinter as tk
from ttkcalendar import Calendar
def test2():
import sys
root = tk.Tk()
root.title('Ttk Calendar')
ttkcal = Calendar(firstweekday=calendar.SUNDAY)
ttkcal.pack(expand=1, fill='both')
if 'win' not in sys.platform:
style = ttk.Style()
style.theme_use('clam')
root.mainloop()
x = ttkcal.selection
print('x is: {}'.format(x))
test2()
... Python 3.4.3 works, too, as does the most recent compiled-from-source
version I have lying around,
$ python3.7
Python 3.7.0a0 (default:09d4d47ad210, Jan 31 2017, 22:08:14)
[GCC 4.8.4] on linux
The underlying tcl is 8.6.
More information about the Tutor
mailing list