Title: Accessing a tkinter object's string representation converts the object to a string on Windows · Issue #101830 · python/cpython · GitHub
Open Graph Title: Accessing a tkinter object's string representation converts the object to a string on Windows · Issue #101830 · python/cpython
X Title: Accessing a tkinter object's string representation converts the object to a string on Windows · Issue #101830 · python/cpython
Description: Introduced in #16545 Affects Python 3.7+ on Windows only The FromObj function in _tkinter.c attempt to convert a Tcl_Obj to an equivalent Python object if possible, and otherwise returns a _tkinter.Tcl_Obj with the typename attribute set...
Open Graph Description: Introduced in #16545 Affects Python 3.7+ on Windows only The FromObj function in _tkinter.c attempt to convert a Tcl_Obj to an equivalent Python object if possible, and otherwise returns a _tkinter...
X Description: Introduced in #16545 Affects Python 3.7+ on Windows only The FromObj function in _tkinter.c attempt to convert a Tcl_Obj to an equivalent Python object if possible, and otherwise returns a _tkinter...
Opengraph URL: https://github.com/python/cpython/issues/101830
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Accessing a tkinter object's string representation converts the object to a string on Windows","articleBody":"Introduced in #16545\r\nAffects Python 3.7+ on Windows only\r\n\r\n---\r\n\r\nThe [`FromObj`](https://github.com/python/cpython/blob/3eb12df8b526aa5a2ca6b43f21a1c5e7d38ee634/Modules/_tkinter.c#L1115) function in `_tkinter.c` attempt to convert a `Tcl_Obj` to an equivalent Python object if possible, and otherwise returns a `_tkinter.Tcl_Obj` with the `typename` attribute set to the original object's type.\r\n\r\nHowever, on Windows, accessing the resulting object's string representation [calls `Tcl_GetUnicodeFromObj`](https://github.com/python/cpython/blob/3eb12df8b526aa5a2ca6b43f21a1c5e7d38ee634/Modules/_tkinter.c#L492), which converts the `Tcl_Obj` to a `String`. This side effect isn't mentioned in the Tcl documentation, but is [in the Tcl source code](https://github.com/tcltk/tcl/blob/c529405c659f132d217336a626895a13a0ecaef0/generic/tclStringObj.c#L655-L672). As a result, retrieving the same tk property afterwards will return a Python string instead.\r\n\r\nMinimal example:\r\n```py\r\nimport tkinter as tk\r\n\r\nroot = tk.Tk()\r\nprint(type(root.cget(\"padx\")))\r\n_ = str(root.cget(\"padx\")) # should really not cause any side effects\r\nprint(type(root.cget(\"padx\")))\r\n\r\n# Windows:\r\n# \u003cclass '_tkinter.Tcl_Obj'\u003e\r\n# \u003cclass 'str'\u003e\r\n# Other platforms:\r\n# \u003cclass '_tkinter.Tcl_Obj'\u003e\r\n# \u003cclass '_tkinter.Tcl_Obj'\u003e\r\n```\r\n\r\n---\r\n\r\nPossible solutions: `unicodeFromTclObj` should copy the object before passing calling `Tcl_GetUnicodeFromObj`, or handle Unicode without it like on other platforms.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-120884\n* gh-120905\n* gh-120913\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/daniilS","@type":"Person","name":"daniilS"},"datePublished":"2023-02-11T19:57:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/101830/cpython/issues/101830"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c9b78099-0336-f9df-4d33-461b103fbfd5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5BE:16DD22:EF1DE8:1495E16:6A4DD456 |
| html-safe-nonce | c7592ce059ff0fa7cefc4e7337fe07483fdc73e07ada5eba2b81aa7b2610d8c2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUJFOjE2REQyMjpFRjFERTg6MTQ5NUUxNjo2QTRERDQ1NiIsInZpc2l0b3JfaWQiOiIzMjA4MzYxNzg5MDMzOTI3NzY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a918005d275e5743764deb10052539b344500a7f1cba2a3f885efbfbd758bffb |
| hovercard-subject-tag | issue:1580994154 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/101830/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68f5392a3ea720ba738510dee0403a188d61e0064c780997f9ff9ec9aed8ca3d/python/cpython/issues/101830 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68f5392a3ea720ba738510dee0403a188d61e0064c780997f9ff9ec9aed8ca3d/python/cpython/issues/101830 |
| og:image:alt | Introduced in #16545 Affects Python 3.7+ on Windows only The FromObj function in _tkinter.c attempt to convert a Tcl_Obj to an equivalent Python object if possible, and otherwise returns a _tkinter... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | daniilS |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width