Using TKinter to show popular tweets from twitter API (Tweepy)

Terry Reedy tjreedy at
Wed Apr 5 17:31:31 EDT 2017

On 4/5/2017 3:48 PM, unihno at wrote:

> I'm building a python app where it should show the popular tweets
 > in boxes in line with each other using TKinter.

By 'boxes' do you mean a visible border for Label widgets?  If so, you 
have to configure one.  You don't below.

 > The problem is that the labels of the tweets are showing at
 > the bottom of each other

I don't understand this, and cannot run your code to see what it does.

> and i want them to be in boxes like this:


> this is my code:
> from Tkinter import *
> import tweepy
> from local import *
> import Tkinter as tk

Use just 1 of the 2 tkinter imports.

> auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
> auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
> auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
> auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
> api = tweepy.API(auth)

For initial development of the UI, and especially when asking for help, 
use static data included within the file.  In this case, a short list of 
'status' items with the required attributes.  Read

>         for status in tweepy.Cursor(, q=trend['name'], result_type='popular').items(1):

     for status in myshortlist:

>             f = tk.Frame(root, background='black', borderwidth=2, relief="groove").pack()

Commen error.
.pack(), etc is a status mutation method and returns None.
You did not get an exception only because f is not used.

>             Label(text=('@' + status.user.screen_name, "tweeted: ",status.text)).pack()

You omitted the master, so it defaults to the more or less undocumented 
default root.  It this context, this should be the explicit 'root' 
defined previously.  I recommend being explicit, always.

I did not know that the 'string' passed as 'text' could be a tuple of 
strings.  I don't know if it is documented anywhere.  My simple 
experiment suggested that the result is ' '.join(strings), as with print 
calls.  But I don't know it that is always true.

Multiple Labels should be packed vertically, with each centered.  If you 
want lined up to the left, you will have to say so.  As I said, I don't 
know what you saw.

 > Please help

Please make it easier by posting a better question, including an mcve.

Terry Jan Reedy

More information about the Python-list mailing list