mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
gh-91827: Add method info_pathlevel() in tkinter (GH-91829)
This commit is contained in:
parent
d707d073be
commit
15dbe8570f
8 changed files with 75 additions and 23 deletions
|
|
@ -30,6 +30,7 @@ button.pack(side=BOTTOM)
|
|||
tk.mainloop()
|
||||
"""
|
||||
|
||||
import collections
|
||||
import enum
|
||||
import sys
|
||||
import types
|
||||
|
|
@ -143,6 +144,28 @@ def _splitdict(tk, v, cut_minus=True, conv=None):
|
|||
dict[key] = value
|
||||
return dict
|
||||
|
||||
class _VersionInfoType(collections.namedtuple('_VersionInfoType',
|
||||
('major', 'minor', 'micro', 'releaselevel', 'serial'))):
|
||||
def __str__(self):
|
||||
if self.releaselevel == 'final':
|
||||
return f'{self.major}.{self.minor}.{self.micro}'
|
||||
else:
|
||||
return f'{self.major}.{self.minor}{self.releaselevel[0]}{self.serial}'
|
||||
|
||||
def _parse_version(version):
|
||||
import re
|
||||
m = re.fullmatch(r'(\d+)\.(\d+)([ab.])(\d+)', version)
|
||||
major, minor, releaselevel, serial = m.groups()
|
||||
major, minor, serial = int(major), int(minor), int(serial)
|
||||
if releaselevel == '.':
|
||||
micro = serial
|
||||
serial = 0
|
||||
releaselevel = 'final'
|
||||
else:
|
||||
micro = 0
|
||||
releaselevel = {'a': 'alpha', 'b': 'beta'}[releaselevel]
|
||||
return _VersionInfoType(major, minor, micro, releaselevel, serial)
|
||||
|
||||
|
||||
@enum._simple_enum(enum.StrEnum)
|
||||
class EventType:
|
||||
|
|
@ -1055,6 +1078,11 @@ class Misc:
|
|||
|
||||
lift = tkraise
|
||||
|
||||
def info_patchlevel(self):
|
||||
"""Returns the exact version of the Tcl library."""
|
||||
patchlevel = self.tk.call('info', 'patchlevel')
|
||||
return _parse_version(patchlevel)
|
||||
|
||||
def winfo_atom(self, name, displayof=0):
|
||||
"""Return integer which represents atom NAME."""
|
||||
args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue