Guest User

GUI

a guest
Nov 17th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. import Tkinter
  2. from Tkinter import *
  3. from ScrolledText import *
  4. import tkFileDialog
  5. import tkMessageBox
  6. import time
  7.  
  8. keybord_string = "qwertyuiopasdfghjklzxcvbnm"
  9. #[]{};:''|<>,./?1234567890-=!@#$%^&*()_+\\`~
  10. root = Tkinter.Tk(className=" Collaborative Text Editor")
  11. textPad = ScrolledText(root, width=100, height=80)
  12.  
  13.  
  14.  
  15. ''' Uploading of file received from server
  16.  
  17. contents = file.read()
  18. textPad.insert('1.0', contents)
  19. file.close()
  20.  
  21. '''
  22. # create a menu & define functions for each menu item
  23.  
  24. def open_command():
  25. file = tkFileDialog.askopenfile(parent=root, mode='rb', title='Select a file')
  26. if file != None:
  27. contents = file.read()
  28. textPad.insert('1.0', contents)
  29. file.close()
  30.  
  31.  
  32. def save_command(self):
  33. file = tkFileDialog.asksaveasfile(mode='w')
  34. if file != None:
  35. # slice off the last character from get, as an extra return is added
  36. data = self.textPad.get('1.0', END + '-1c')
  37. file.write(data)
  38. file.close()
  39.  
  40.  
  41. def exit_command():
  42. if tkMessageBox.askokcancel("Quit", "Do you really want to quit?"):
  43. root.destroy()
  44.  
  45.  
  46. def about_command():
  47. label = tkMessageBox.showinfo("About", "Just Another TextPad \n Copyright \n No rights left to reserve")
  48.  
  49.  
  50. def dummy():
  51. print "I am a Dummy Command, I will be removed in the next step"
  52.  
  53. def getText():
  54. return textPad.get(1.0, END)
  55.  
  56.  
  57. def get_info():
  58. print textPad.index(INSERT)
  59. textPad.insert(INSERT, "Some text")
  60. print textPad.index(INSERT)
  61.  
  62. def key_enter(event):
  63. s = textPad.index(INSERT)
  64. print s
  65.  
  66.  
  67.  
  68. def key_backspace(event):
  69. pass
  70.  
  71. def key_disable(event):
  72. textPad.config(state=DISABLED)
  73.  
  74. def key(event):
  75. s = textPad.index(INSERT)
  76. point_index = s.index(".")
  77. index1 = int(s[:point_index])
  78. index2 = int(s[point_index+1:])
  79. out = textPad.get("%d.%d" % (index1, index2 - 1), "%d.%d" % (index1, index2))
  80. if out:
  81. print s,out
  82.  
  83. def key_press(event):
  84. textPad.config(state=DISABLED)
  85. time.sleep(0.3)
  86. textPad.config(state=NORMAL)
  87.  
  88.  
  89. menu = Menu(root)
  90. root.config(menu=menu)
  91. filemenu = Menu(menu)
  92. menu.add_cascade(label="File", menu=filemenu)
  93. filemenu.add_command(label="New", command=dummy)
  94. filemenu.add_command(label="Open...", command=open_command)
  95. filemenu.add_command(label="Save", command=save_command)
  96. filemenu.add_separator()
  97. filemenu.add_command(label="Exit", command=exit_command)
  98. helpmenu = Menu(menu)
  99. menu.add_cascade(label="Help", menu=helpmenu)
  100. helpmenu.add_command(label="About...", command=about_command)
  101.  
  102. textPad.bind("<Control-v>", key_disable)
  103. textPad.bind("<Return>", key_enter)
  104. textPad.bind("<BackSpace>", key_backspace)
  105. textPad.bind("<Key>", key_press)
  106. textPad.bind("<KeyRelease>", key)
  107.  
  108.  
  109. textPad.pack()
  110. root.mainloop()
Add Comment
Please, Sign In to add comment