chatwindowGUI.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. import Tkinter as tk
  2. import scrollable_frame
  3. class ChatWindowGUI(tk.Tk):
  4. def __init__(self, keypress):
  5. tk.Tk.__init__(self)
  6. self.resizable(width=tk.FALSE, height=tk.FALSE)
  7. self.width = 230
  8. self.height = 100
  9. self.labelwidth = 30
  10. self.frame = tk.Frame(self)
  11. self.frame.focus_set()
  12. self.frame.bind('<Key>', keypress)
  13. self.chat_field = scrollable_frame.VerticalScrolledFrame(self.frame, bd='2', height=self.height, width=self.width, relief=tk.RIDGE)
  14. tk.Label(self.chat_field.interior, text='SCCD Chat Client -- Tk version', justify=tk.LEFT, anchor=tk.NW, width=self.labelwidth).pack()
  15. self.tk_buffer = tk.StringVar()
  16. input_frame = tk.Frame(self.frame, bd='2', height=100, width=self.width, relief=tk.RIDGE)
  17. self.input_text = tk.Label(input_frame, textvar=self.tk_buffer, anchor=tk.NW, justify=tk.LEFT, wraplength=self.width, width=self.labelwidth, background='grey')
  18. self.chat_field.pack(anchor=tk.NW)
  19. input_frame.pack(anchor=tk.NW, fill=tk.X)
  20. self.input_text.pack(anchor=tk.NW, fill=tk.X)
  21. self.frame.pack(anchor=tk.NW)
  22. def redraw_buffer(self, text):
  23. self.tk_buffer.set(text)
  24. def setColor(self, color):
  25. self.input_text.configure(background=color)
  26. def addMessage(self, msg, color):
  27. tk.Label(self.chat_field.interior, text=msg, anchor=tk.NW, justify=tk.LEFT, foreground=color, wraplength=230, width=30).pack(anchor=tk.NW)