tkinter.tclerror: character u+1f449 is above the range (u+0000-u+ffff) allowed by tcl

  • Last Update :
  • Techknowledgy :

The easiest way to do this would be to strip out the extra characters. This could be done with the following code at the start of the for loop:

char_list = [tweet[j]
   for j in range(len(tweet)) if ord(tweet[j]) in range(65536)
]
tweet = ''
for j in char_list:
   tweet = tweet + j

I took the solution posted there an adapted it to processing gmail messages where the Subject line somehow has incorrect characters inserted sometimes:

try:
iid = self.lib_tree.insert("", tk.END, tags = "unchecked",
   values = (message_id, subject, sender, epoch, date, labels,
      snippet))
except tk.TclError:
   print('old subject:', subject)

import re

# From: https: //bugs.python.org/issue21084
   astral = re.compile(r '([^\x00-\uffff])')
s = subject
new_subject = ""
for i, ss in enumerate(re.split(astral, s)):
   if not i % 2:
   new_subject += ss
else:
   new_subject += '?'
print('new_subject:', new_subject)
continue

Output from program loading about 5,000 gmail messages:

$ bserve.py
old subject: Mserve June 18 / 2021
new_subject: Mser ? e June 18 / 2021
old subject: mserve December 7, 2020
new_subject: mser ? e December 7, 2020
old subject: Re: WinEunuuchs2Unix
new_subject: Re: WinEunuuchs2Uni ?
   old subject : 🚚ORDER UPDATE: 2019 Cigarette Light...
   new_subject: ? ORDER UPDATE : 2019 Cigarette Light...
   old subject: 📌You 've got 18 new ideas waiting for you!
new_subject: ? You '?e got 18 ne? ideas ?aiting for ?ou!
old subject: 🔥Get inspired with these 18 trending ideas
new_subject: ? Get inspired ? ith these 18 trending ideas
old subject: 🔥18 popular Pins
for you
new_subject: ? 18 popular Pins
for ? ou
old subject: 🔥Get inspired with these 18 trending ideas
new_subject: ? Get inspired ? ith these 18 trending ideas
old subject: 🔥Get inspired with these 18 trending ideas
new_subject: ? Get inspired ? ith these 18 trending ideas
old subject: 📌You 've got 18 new ideas waiting for you!
new_subject: ? You '?e got 18 ne? ideas ?aiting for ?ou!
old subject: 📌We picked some Puzzle art Pins
for you
new_subject: ? We picked some Pu ?? le art Pins
for ? ou
old subject: 🔵INFANTRY Mens LCD Digital Quartz Wrist Watch Tactical Sport Stainless Steel Navy is HOT on eBay, but quantity is limited
new_subject: ? INFANTRY Mens LCD Digital Quart ? Wrist Watch Tactical Sport Stainless Steel Na ?? is HOT on eBa ? , but quantit ? is limited
old subject: 🔵POLJOT AVIATOR ATTACK PLANE MEN`S  RUSSIAN MILITARY WATCH is HOT on eBay, but quantity is limited
new_subject: ? POLJOT AVIATOR ATTACK PLANE MEN`
S RUSSIAN MILITARY WATCH is HOT on eBa ? , but quantit ? is limited

Suggestion : 2

_tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl

我正在尝试使用 tweepy 在 Tkinter 窗口上显示我的 twitter 时间线。这是代码

import tweepy
import tkinter

consumer_key = 'xxxxxxxxxxxxxx'
consumer_sec = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token_sec = 'xxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(consumer_key, consumer_sec)
auth.set_access_token(acc_token, acc_token_sec)

api = tweepy.API(auth)

tweets = api.home_timeline()

tkwindow = tkinter.Tk()

for tweet in tweets:
   i = 1
label = tkinter.Label(tkwindow, text = tweet.author.name + " " + str(tweet.created_at) + "\n" + str(tweet.text))
if i == 5:
   break
tkwindow.mainloop()

最简单的方法是去掉多余的字符。这可以在 for 循环开始时使用以下代码完成:

char_list = [tweet[j]
   for j in range(len(tweet)) if ord(tweet[j]) in range(65536)
]
tweet = ''
for j in char_list:
   tweet = tweet + j

Suggestion : 3

Help Tracker Documentation Tracker Development Report Tracker Problem ,This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide.

When open a file with characters above the range(U + 0000 - U + FFFF), IDLE quit without any report.For example, open this file\ Lib\ test\ test_re.py

The below is Traceback info, the last line tells the reason.I just hope IDLE say something before quit, so we can know what happend.

I have checked Python 3.3 .5 and 3.4 .0, they have the same problem.I didn 't find a 3.5 build, so I can'
t test this problem under 3.5.

   ===
   === === === === === === === === === === === === === ===
   Exception in Tkinter callback
Traceback(most recent call last):
   File "C:\Python33\lib\tkinter\__init__.py", line 1489, in __call__
return self.func( * args)
File "C:\Python33\lib\idlelib\IOBinding.py", line 186, in open
flist.open(filename)
File "C:\Python33\lib\idlelib\FileList.py", line 36, in open
edit = self.EditorWindow(self, filename, key)
File "C:\Python33\lib\idlelib\PyShell.py", line 126, in __init__
EditorWindow.__init__(self, * args)
File "C:\Python33\lib\idlelib\EditorWindow.py", line 288, in __init__
if io.loadfile(filename):
   File "C:\Python33\lib\idlelib\IOBinding.py", line 236, in loadfile
self.text.insert("1.0", chars)
File "C:\Python33\lib\idlelib\Percolator.py", line 25, in insert
self.top.insert(index, chars, tags)
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 81, in insert
self.addcmd(InsertCommand(index, chars, tags))
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 116, in addcmd
cmd.do(self.delegate)
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 219, in do
      text.insert(self.index1, self.chars, self.tags)
   File "C:\Python33\lib\idlelib\ColorDelegator.py", line 85, in insert
self.delegate.insert(index, chars, tags)
File "C:\Python33\lib\idlelib\WidgetRedirector.py", line 104, in __call__
return self.tk_call(self.orig_and_operation + args)
_tkinter.TclError: character U + 1 d518 is above the range(U + 0000 - U + FFFF) allowed by Tcl
When open a file with characters above the range(U + 0000 - U + FFFF), IDLE quit without any report.For example, open this file C: \Python33\ lib\ test\ test_re.py

The below is Traceback info, the last line tells the reason.I just hope IDLE say something before quit, so we can know what happend.

I have checked Python 3.3 .5 and 3.4 .0, they have the same problem.I didn 't find a 3.5 build, so I can'
t test this problem under 3.5.

   ===
   === === === === === === === === === === === === === ===
   Exception in Tkinter callback
Traceback(most recent call last):
   File "C:\Python33\lib\tkinter\__init__.py", line 1489, in __call__
return self.func( * args)
File "C:\Python33\lib\idlelib\IOBinding.py", line 186, in open
flist.open(filename)
File "C:\Python33\lib\idlelib\FileList.py", line 36, in open
edit = self.EditorWindow(self, filename, key)
File "C:\Python33\lib\idlelib\PyShell.py", line 126, in __init__
EditorWindow.__init__(self, * args)
File "C:\Python33\lib\idlelib\EditorWindow.py", line 288, in __init__
if io.loadfile(filename):
   File "C:\Python33\lib\idlelib\IOBinding.py", line 236, in loadfile
self.text.insert("1.0", chars)
File "C:\Python33\lib\idlelib\Percolator.py", line 25, in insert
self.top.insert(index, chars, tags)
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 81, in insert
self.addcmd(InsertCommand(index, chars, tags))
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 116, in addcmd
cmd.do(self.delegate)
File "C:\Python33\lib\idlelib\UndoDelegator.py", line 219, in do
      text.insert(self.index1, self.chars, self.tags)
   File "C:\Python33\lib\idlelib\ColorDelegator.py", line 85, in insert
self.delegate.insert(index, chars, tags)
File "C:\Python33\lib\idlelib\WidgetRedirector.py", line 104, in __call__
return self.tk_call(self.orig_and_operation + args)
_tkinter.TclError: character U + 1 d518 is above the range(U + 0000 - U + FFFF) allowed by Tcl
See #13153.
Accidentally set to pending I take it.
Yes, this is very similar to issue13153.Both these issues can have same solution or can have different solutions.This issue relates to more realistic situation and therefore is more important.

Here is simple and almost working solution
for this issue.Unfortunately it works incorrectly when astral characters are encountered in raw string literals.More mature solution should parse sources and convert raw string literals containing astral characters to non - raw string literals.But this will not work with invalid Python files and non - Python files.

I afraid this issue has not perfect solution.The question is which imperfect solution and compromise we will decided enough acceptable.
I suggest don 't change the content of file, just give a message such as:

IDLE can 't display non-BMP character (codepoint above 0xFFFF).
A non - BMP character found in Line 23, position 8 of aaaa.py, please open this file with other editor.

Suggestion : 4

_tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl,tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF),_tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF),这篇关于tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

I am trying to show my twitter timeline on Tkinter window using tweepy. This is the code

import tweepy
import tkinter

consumer_key = 'xxxxxxxxxxxxxx'
consumer_sec = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token_sec = 'xxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(consumer_key, consumer_sec)
auth.set_access_token(acc_token, acc_token_sec)

api = tweepy.API(auth)

tweets = api.home_timeline()

tkwindow = tkinter.Tk()

for tweet in tweets:
   i = 1
label = tkinter.Label(tkwindow, text = tweet.author.name + " " + str(tweet.created_at) + "\n" + str(tweet.text))
if i == 5:
   break
tkwindow.mainloop()

The easiest way to do this would be to strip out the extra characters. This could be done with the following code at the start of the for loop:

char_list = [tweet[j]
   for j in range(len(tweet)) if ord(tweet[j]) in range(65536)
]
tweet = ''
for j in char_list:
   tweet = tweet + j

Suggestion : 5

The Tkinter module is included with core Python, of course, but you'll need a version of Tcl/Tk on your system to compile it against. Do yourself a huge favor and get the most recent version.,Next, download the current Python 3.x source distribution from python.org, and unpack it. On your configure line, you'll need to tell it how to find the version of Tcl/Tk you installed. Then build as usual:,If you're instead building Python from source code, the Visual Studio projects included in the "PCbuild" directory can automatically fetch and compile Tcl/Tk on your system.,As noted, the easiest way to get Tk and Tkinter installed on your system is using Python's binary installer, available at python.org. Thanks to work by Python core developer Ned Deily, binary installers starting with version 3.7 include Tcl and Tk.

If you're using Python 3.9 or newer, the build system will look in /Library/Frameworks, where ActiveState and other custom builds are typically installed.

% . / configure
   %
   make

When compiling Python versions prior to 3.9, you will need to add two new command-line options to the initial ./configure in the Python build process. The first provides the locations of the Tcl and Tk include files, and the second provides the locations of the Tcl and Tk libraries. These are usually found in two different locations (i.e., Tcl.framework and Tk.framework). You need to provide both locations for the include files and both for the libraries. Note the location of the quotes in the command below and the spaces separating the Tcl and Tk paths.

% . / configure--with - tcltk - includes = "-I/Library/Frameworks/Tcl.framework/Headers -I/Library/Frameworks/Tk.framework/Headers"--with - tcltk - libs = "/Library/Frameworks/Tcl.framework/Tcl /Library/Frameworks/Tk.framework/Tk" %
   make

When everything is built, be sure to test it out. Start Python from your terminal, e.g.

% . / python.exe

You can also get the exact version of Tcl/Tk that is being used with:

>>> tkinter.Tcl().eval('info patchlevel')

To verify the exact version of Tcl/Tk that you are running, from the Wish console type the following:

% info patchlevel

Next, you'll want to install Ruby. There are multiple ways to do this, as explained at www.ruby-lang.org. One option is to use a package manager like Homebrew. Once it's been installed (at /usr/local/bin/brew) you can install Ruby from a command prompt (e.g. Terminal) via:

% brew install ruby

Next, you'll need to download and install Ruby's Tk module, which is packaged as a Ruby gem. To do so, from the command prompt, run:

% /usr/local / opt / ruby / bin / gem install tk

To verify that everything worked, start up /usr/local/opt/ruby/bin/irb and type:

% require 'tk' %
   Tk::TK_PATCHLEVEL

Next, you'll want to install Perl. There are multiple ways to do this, as explained at www.perl.org. One option is to use a package manager like Homebrew. Once it's been installed (at /usr/local/bin/brew) you can install Ruby from a command prompt (e.g. Terminal) via:

% brew install perl

Next, you'll need to download and install Perl's Tkx module. We can grab it from CPAN. Unfortunately, at present it will not install correctly due to errors in its tests. We can bypass the tests and install it anyway. To do so, from the command prompt, run:

% /usr/local / opt / perl / bin / perl - MCPAN - e "CPAN::Shell->notest('install','Tkx')"

To check that this worked, run this from the Unix command line:

% /usr/local / opt / perl / bin / perl - MTkx - e 'print Tkx::info("patchlevel");'

Once you've installed or compiled Python, test it out to make sure Tkinter works. From the Python prompt, enter these two commands:

>>>
import tkinter
   >>>
   tkinter._test()

You can also get the exact version of Tcl/Tk that is being used with:

>>> tkinter.Tcl().eval('info patchlevel')

Run the installer, and follow along. You'll end up with a fresh install of ActiveTcl, usually located in C:\ActiveTcl. From a command prompt, you should then be able to run a Tcl/Tk 8.6 shell via:

% C: \ActiveTcl\ bin\ wish

This should pop up a small window titled "wish", which will contain your application. A second, larger window titled "Console" is where you can type in Tcl/Tk commands. To verify the exact version of Tcl/Tk that you are running, type the following:

% info patchlevel