tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF) [英] tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl

查看:58
本文介绍了tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但我有以下错误

_tkinter.TclError: 字符 U+1f449 超出了 Tcl 允许的范围 (U+0000-U+FFFF)

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

我知道 tkinter 无法显示一些出现在真实推文中的特殊图标,但实际上,我不想显示那些,我只想显示推文的简单文本,

I understand that tkinter can't show some special icons which appear in real tweets, But actually, I don't want to show those, I just want to show simple text of the tweet,

那么我如何避免这个错误并只显示推文的文本

So How I can avoid this error and show only text of the tweets

推荐答案

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆