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()
But I am having following error
_tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With