SubredditWidgets¶
- class praw.models.SubredditWidgets(subreddit)¶
Class to represent a
Subreddit’s widgets.Create an instance like so:
widgets = reddit.subreddit("test").widgets
Data will be lazy-loaded. By default, PRAW will not request progressively loading images from Reddit. To enable this, instantiate a
SubredditWidgetsobject viawidgets(), then set the attributeprogressive_imagestoTruebefore performing any action that would result in a network request.widgets = reddit.subreddit("test").widgets widgets.progressive_images = True for widget in widgets.sidebar: # do something ...
Access a
Subreddit’s widgets with the following attributes:print(widgets.id_card) print(widgets.moderators_widget) print(widgets.sidebar) print(widgets.topbar)
The attribute
id_cardcontains theSubreddit’s ID card, which displays information like the number of subscribers.The attribute
moderators_widgetcontains theSubreddit’s moderators widget, which lists the moderators of the subreddit.The attribute
sidebarcontains a list of widgets which make up the sidebar of the subreddit.The attribute
topbarcontains a list of widgets which make up the top bar of the subreddit.To edit a
Subreddit’s widgets, usemod. For example:widgets.mod.add_text_area( short_name="My title", text="**bold text**", styles={"backgroundColor": "#FFFF66", "headerColor": "#3333EE"}, )
For more information, see
SubredditWidgetsModeration.To edit a particular widget, use
.modon the widget. For example:for widget in widgets.sidebar: widget.mod.update(shortName="Exciting new name")
For more information, see
WidgetModeration.Currently available widgets:
- Parameters:
subreddit (models.Subreddit)
- __init__(subreddit)¶
Initialize a
SubredditWidgetsinstance.
- mod()¶
Get an instance of
SubredditWidgetsModeration.Note
Using any of the methods of
SubredditWidgetsModerationwill likely result in the data of thisSubredditWidgetsbeing outdated. To re-sync, callrefresh().- Return type:
- moderators_widget()¶
Get this
Subreddit’sModeratorsWidget.- Return type:
- classmethod parse(data, reddit)¶
Return an instance of
clsfromdata.
- refresh()¶
Refresh the
Subreddit’s widgets.By default, PRAW will not request progressively loading images from Reddit. To enable this, set the attribute
progressive_imagestoTrueprior to callingrefresh().widgets = reddit.subreddit("test").widgets widgets.progressive_images = True widgets.refresh()
- Return type: