Advertisement
Guest User

Untitled

a guest
May 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. from Tkinter import *
  4. from twitter import *
  5. import sys
  6. import tkMessageBox
  7. import urllib2
  8.  
  9. def Quit():
  10. RealRoot.destroy()
  11.  
  12. class TopWindow(Toplevel):
  13.  
  14. def __init__(self,name,**k):
  15. Toplevel.__init__(self,border=4,**k)
  16. self.master.withdraw() # hide real tk root
  17. self.title(name)
  18.  
  19. def run(self):
  20. self.center()
  21. self.focus()
  22.  
  23. def focus(self):
  24. self.grab_set()
  25. self.focus_set()
  26.  
  27. def center(self):
  28. self.update_idletasks()
  29. w= self["width"]!=0 and self["width"] or self.winfo_width()
  30. h= self["height"]!=0 and self["height"] or self.winfo_height()
  31. ws,hs = self.winfo_screenwidth(),self.winfo_screenheight()
  32. self.geometry('%dx%d+%d+%d' % (w, h, (ws/2) - (w/2), (hs/2) - (h/2)))
  33.  
  34. ################## UNUSED ROOT WINDOW#######################################################
  35. RealRoot=Tk()
  36.  
  37. RealRoot.title("Jason Twitter Client")
  38. RealRoot.config(bg="light blue")
  39. RealRoot.protocol("WM_DELETE_WINDOW",RealRoot.quit)
  40.  
  41. ############ USER CREDENTIAL WINDOW ######################################################
  42.  
  43. def AttemptLogin():
  44. name=UsernameEntry.get()
  45. password=PasswordEntry.get()
  46. API=twitter.Api(username=name,password=password)
  47. try:
  48. API.GetFriends()
  49. CredWindow.destroy()
  50. except urllib2.HTTPError:
  51. CredWindow.showerror("Login Error","Incorrect username or password")
  52.  
  53.  
  54. CredWindow=TopWindow("User Credentials")
  55. CredWindow.protocol("WM_DELET_WINDOW",RealRoot.quit)
  56. CredText=Label(CredWindow,text="Welcome to pyTweet!")
  57. CredText.grid(column=0,row=0,columnspan=2,sticky=N+S+E+W)
  58.  
  59. UsernameText=Label(CredWindow,text="Username:")
  60. UsernameText.grid(column=0,row=1,sticky=N+S+E+W)
  61.  
  62. PasswordText=Label(CredWindow,text="Password:")
  63. PasswordText.grid(column=0,row=2,sticky=N+S+E+W)
  64.  
  65. UsernameEntry=Entry(CredWindow)
  66. UsernameEntry.grid(column=1,row=1,sticky=N+S+E+W)
  67.  
  68. PasswordEntry=Entry(CredWindow,show="*")
  69. PasswordEntry.grid(column=1,row=2,sticky=N+S+E+W)
  70.  
  71. LoginButton=Button(CredWindow,text="Login",command=AttemptLogin)
  72. LoginButton.grid(column=0,row=3,columnspan=2)
  73. CredWindow.run()
  74. CredWindow.wait_window()
  75.  
  76. ################# MAIN WINDOW #####################################################
  77.  
  78. Root=TopWindow("Jason Twitter Client")
  79. Root.protocol("WM_DELETE_WINDOW",Quit)
  80. Status=Label(Root,text="Status:",bg="light blue")
  81. Status.grid(column=1,row=0,sticky=N+S+E+W)
  82.  
  83. StatusText=Text(Root,bg="white",height=2)
  84. StatusText.grid(column=2,row=0,columnspan=5,sticky=N+S+E+W)
  85.  
  86. Refresh=Button(Root,text="Refresh")
  87. Refresh.grid(column=8,row=0,sticky=N+S+E+W)
  88.  
  89. DisplayScroll=Scrollbar(Root,orient=VERTICAL)
  90. DisplayScroll.grid(column=8,row=2,rowspan=8,sticky=N+S+W)
  91.  
  92. Display=Text(Root,bg="white",yscrollcommand=DisplayScroll.set)
  93. Display.grid(column=3,row=2,columnspan=5,rowspan=9,sticky=N+S+E+W)
  94.  
  95. DisplayScroll["command"]=Display.yview
  96.  
  97. Home=Button(Root,text="Home")
  98. Home.grid(column=0,row=1,sticky=N+S+E+W)
  99.  
  100. Profile=Button(Root,text="Profile")
  101. Profile.grid(column=1,row=1,sticky=N+S+E+W)
  102.  
  103. ChoiceVar=IntVar()
  104.  
  105. FriendChoice=Radiobutton(Root,text="Friends",variable=ChoiceVar,value=0,bg="light blue")
  106. FriendChoice.grid(column=0,row=2,columnspan=2,sticky=W)
  107.  
  108. FollowerChoice=Radiobutton(Root,text="Followers",variable=ChoiceVar,value=1,bg="light blue")
  109. FollowerChoice.grid(column=0,row=3,columnspan=2,sticky=W)
  110.  
  111. UserScroll=Scrollbar(Root,orient=VERTICAL)
  112. UserScroll.grid(column=2,row=4,rowspan=5,sticky=N+S)
  113.  
  114. Users=Listbox(Root,bg="white",height=15,yscrollcommand=UserScroll.set)
  115. Users.grid(column=0,row=4,rowspan=5,columnspan=2)
  116.  
  117. UserScroll["command"]=Users.yview
  118.  
  119. Search=Label(Root,text="Search:")
  120. Search.grid(column=3,row=1,sticky=N+S+E+W)
  121.  
  122. SearchText=Entry(Root,bg="white")
  123. SearchText.grid(column=4,row=1,columnspan=3,sticky=N+S+E+W)
  124.  
  125. SearchButton=Button(Root,text="Search")
  126. SearchButton.grid(column=8,row=1,sticky=N+S+E+W)
  127.  
  128. TweetLabel=Label(Root,text="Tweet:")
  129. TweetLabel.grid(column=3,row=10,sticky=N+S+E+W)
  130.  
  131. TweetText=Entry(Root,bg="white")
  132. TweetText.grid(column=4,row=10,columnspan=3,sticky=N+S+E+W)
  133.  
  134. TweetButton=Button(Root,text="Tweet")
  135. TweetButton.grid(column=8,row=10,sticky=N+S+E+W)
  136.  
  137. CharsLeft=Message(Root,text="140",bg="light blue")
  138. CharsLeft.grid(column=8,row=9)
  139.  
  140. Root.run()
  141.  
  142. ##################### FRIEND WINDOW ################################################
  143. FriendWindow=TopWindow("Twitter Activity")
  144.  
  145. InfoDisplayScroll=Scrollbar(FriendWindow,orient=VERTICAL)
  146. InfoDisplayScroll.grid(column=10,row=0,rowspan=8,sticky=N+S+W)
  147.  
  148. InfoDisplay=Text(FriendWindow,yscrollcommand=InfoDisplayScroll.set)
  149. InfoDisplay.grid(column=2,row=0,columnspan=8,rowspan=8,sticky=N+S+E+W)
  150.  
  151. InfoDisplayScroll["command"]=InfoDisplay.yview
  152.  
  153. FollLabel=Label(FriendWindow,text="Followers:")
  154. FollLabel.grid(column=0,row=1,sticky=N+S+E+W)
  155.  
  156. FollInfo=Label(FriendWindow,text="test")
  157. FollInfo.grid(column=1,row=1,sticky=N+S+E+W)
  158.  
  159. FollgLabel=Label(FriendWindow,text="Following:")
  160. FollgLabel.grid(column=0,row=2,sticky=N+S+E+W)
  161.  
  162. FollgInfo=Label(FriendWindow,text="test")
  163. FollgInfo.grid(column=1,row=2,sticky=N+S+E+W)
  164.  
  165. TwLabel=Label(FriendWindow,text="Tweets:")
  166. TwLabel.grid(column=0,row=3,sticky=N+S+E+W)
  167.  
  168. TwInfo=Label(FriendWindow,text="test")
  169. TwInfo.grid(column=1,row=3,sticky=N+S+E+W)
  170.  
  171. TentryLabel=Label(FriendWindow,text="Tweet:")
  172. TentryLabel.grid(column=2,row=8,sticky=N+S+E+W)
  173.  
  174. Tentry=Entry(FriendWindow)
  175. Tentry.grid(column=3,row=8,columnspan=6,sticky=N+S+E+W)
  176.  
  177. ################################################################################
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. Root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement