我使用TKinter来呈现流行的推文(使用tweepy从推特API)。问题是推文的框架位于彼此的底部。我试图改变框架的一面,但没有任何改变。使用TKinter显示彼此相邻的标签
的问题如下所示
我想微博是这样彼此相邻:
这里是我的代码:
from Tkinter import *
import tweepy
from local import *
from PIL import Image, ImageTk
from ttk import Frame, Style
import Tkinter as tk
import ttk
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)
sa_ID = 23424938
large_text_size = 12
text_size = 20
#create obj in the root page (main windows)
root= Tk()
#make bg black
root.configure(background='black')
screenWidth = root.winfo_screenwidth()
screenHeight = root.winfo_screenheight()
root.overrideredirect(1)
root.geometry('%dx%d+0+0' % (screenWidth, screenHeight))
root.configure(background='#000000') # black
canvas = Canvas(
background='#000000', # black
borderwidth=-5,
height=500,
relief='flat',
width=500)
canvas.pack(expand=1, fill=BOTH)
#create invisible container
topframe= tk.Frame(root,background='black')
topframe.pack(side=TOP, fill=BOTH, expand = YES)
label24 = Label(topframe, text="Popular Tweets", bg='black', fg='white',font=('minionpro', text_size)).pack(anchor=CENTER)
bottomframe= Frame(root)
bottomframe.pack(side= BOTTOM)
#, padx=20, pady=20
# name the window
root.title("The news Portal")
trends1 = api.trends_place(id=sa_ID)
data = trends1[0]
# grab the trends
trends = []
trends=data['trends']
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
listbox = Listbox(root, yscrollcommand=scrollbar.set, background='black')
listbox.pack(side=RIGHT)
scrollbar.config(command=listbox.yview)
for trend in trends:
if trend['name'].startswith('#'):
for status in tweepy.Cursor(api.search, q=trend['name'], result_type='popular').items(1):
leftframe = tk.Frame(canvas, background='black', borderwidth=2, relief="groove")
leftframe.pack()
label6 = Label(leftframe, text=('Tweet by: @' + status.user.screen_name, status.text), bg='black',fg='white',
font=('minionpro', large_text_size)).pack(side=BOTTOM,anchor=N)
#label23 = Label(leftframe, text="\n", bg='black', fg='white').pack(side=BOTTOM)
#print status.text
#windows is continously there untill uder close it (never close)
root.mainloop()
事情是我是mi由于这种布局,发布了很多推文。我很感谢你的帮助。
在SO中搜索'[tkinter]网格标签'返回435个结果。我想象一下,前10或20应该有所帮助。 –
我确实搜索过,并且确实应用了多个解决方案,如使用地点,网格,甚至制作for循环。我没有看到你通过写这个评论来添加新的信息:) @TerryJanReedy –
你没有在这个问题中说这个评论的新信息,所以我不知道。很多初学者显然不知道如何搜索,因为简单的搜索会出现重复。无论如何,您所需的输出是一个固定大小的只读文本小部件的网格。可能是因为推特限制。 “标签”或“文字”可能都有效。后者更复杂,但允许不同的字体和大小。 –