本文整理汇总了Python中tkinter.scrolledtext.ScrolledText.yview方法的典型用法代码示例。如果您正苦于以下问题:Python ScrolledText.yview方法的具体用法?Python ScrolledText.yview怎么用?Python ScrolledText.yview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.scrolledtext.ScrolledText
的用法示例。
在下文中一共展示了ScrolledText.yview方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Logger
# 需要导入模块: from tkinter.scrolledtext import ScrolledText [as 别名]
# 或者: from tkinter.scrolledtext.ScrolledText import yview [as 别名]
class Logger(Frame):
ERROR, BORRING, EVENT, NORMAL = "error", "borring", "event", None
def __init__(self, *args, **kw):
text_height = kw.pop("text_height", 25)
Frame.__init__(self, *args, **kw)
self.deque = deque()
self.txt = ScrolledText(self, wrap=WORD, state=DISABLED, relief=SUNKEN, height=text_height)
self.txt.grid(column=0, row=0, sticky=(N, W, E, S))
self.txt.configure(LoggerColors.default)
for k, v in LoggerColors.tags.items():
self.txt.tag_configure(k, v)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.after(100, self._toscreen)
def __call__(self, *args):
self.deque.appendleft(args)
def _toscreen(self):
if len(self.deque):
self.txt["state"] = NORMAL
while(len(self.deque)):
self.txt.insert(
END,
"\n[{}] ".format(strftime("%H:%M:%S")),
"time",
*self.deque.pop())
self.txt.yview(END)
self.txt["state"] = DISABLED
self.after(100, self._toscreen)
示例2: __init__
# 需要导入模块: from tkinter.scrolledtext import ScrolledText [as 别名]
# 或者: from tkinter.scrolledtext.ScrolledText import yview [as 别名]
class GuiPart:
def __init__(self, master, queue,queue2,queue3,endCommand):
self.first_click = True;
self.prefix1='Server says:'#Add the prefix for good display
self.prefix2='Client says:'
#Cause tkinter is not safe in thread, So use queue
#The Python Queue class has been specifically designed to be thread-safe
#in a multi-producer, multi-consumer environment.
self.queue1 = queue
self.queue2 = queue2
self.queue3 = queue3
# Set up the GUI
master.wm_title("Chat Server")
master.resizable('1','1')
self.ui_messages = ScrolledText(
master=master,
wrap=tkinter.WORD,
width=50, # In chars
height=25) # In chars
self.ui_input = tkinter.Text(
master=master,
wrap=tkinter.WORD,
width=50,
height=4)
# Bind the button-1 click of the Entry to the handler
self.ui_input.bind('<Button-1>', self.eventInputClick)
self.ui_button_send = tkinter.Button(
master=master,
text="Send",
command=self.sendMsg)
self.ui_button_file = tkinter.Button(
master=master,
text="File",
command=self.sendFile)
# Compute display position for all objects
self.ui_messages.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_input.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_button_send.pack(side=tkinter.LEFT)
self.ui_button_file.pack(side=tkinter.RIGHT)
# Add more GUI stuff here
print("Starting serverUI...")
self.ui_messages.insert(tkinter.END, "Adding a message to the text field...\n")
self.ui_input.insert(tkinter.END, "<Enter message>")
def processIncoming(self):
"""
Handle all the messages currently in the queue (if any).
"""
while self.queue1.qsize():
try:
msg = self.queue1.get(0)
# Check contents of message and do what it says
# As a test, we simply print it
print (msg)
self.ui_messages.insert(tkinter.INSERT, "%s\n" % (self.prefix2+msg))
self.ui_messages.yview(tkinter.END) # Auto-scrolling
except Queue.Empty:
pass
# SEND button pressed
def sendMsg(self):
# Get user input (minus newline character at end)
msg = self.ui_input.get("0.0", tkinter.END+"-1c")
print("UI: Got text: '%s'" % msg)
# Add this data to the message window
if msg:
self.ui_messages.insert(tkinter.INSERT, "%s\n" % (self.prefix1+msg))
self.ui_messages.yview(tkinter.END) # Auto-scrolling
# Clean out input field for new data
self.ui_input.delete("0.0", tkinter.END)
self.registerEvent(self.queue2,msg)
print("Test: Got text: '%s'" % msg)
def registerEvent(self,container,msg):
container.put(msg)
# FILE button pressed
def sendFile(self):
file = askopenfilename()
if(len(file) > 0 and os.path.isfile(file)):
print("UI: Selected file: %s" % file)
else:
print("UI: File operation canceled")
self.registerEvent(self.queue3,file)
def eventInputClick(self, event):
if(self.first_click):
# If this is the first time the user clicked,
#.........这里部分代码省略.........
示例3: clientUI
# 需要导入模块: from tkinter.scrolledtext import ScrolledText [as 别名]
# 或者: from tkinter.scrolledtext.ScrolledText import yview [as 别名]
class clientUI():
def __init__(self):
self.first_click = True;
def start(self):
print("Starting clientUI...")
self.initDisplay()
self.ui_messages.insert(tkinter.END, "Adding a message to the text field...\n")
self.ui_input.insert(tkinter.END, "<Enter message>")
# This call to mainloop() is blocking and will last for the lifetime
# of the GUI.
self.ui_top.mainloop()
# Should only get here after destroy() is called on ui_top
print("Stopping clientUI...")
def initDisplay(self):
self.ui_top = tkinter.Tk()
self.ui_top.wm_title("GUI Demo")
self.ui_top.resizable('1','1')
self.ui_top.protocol("WM_DELETE_WINDOW", self.eventDeleteDisplay)
self.ui_messages = ScrolledText(
master=self.ui_top,
wrap=tkinter.WORD,
width=50, # In chars
height=25) # In chars
self.ui_input = tkinter.Text(
master=self.ui_top,
wrap=tkinter.WORD,
width=50,
height=4)
# Bind the button-1 click of the Entry to the handler
self.ui_input.bind('<Button-1>', self.eventInputClick)
self.ui_button_send = tkinter.Button(
master=self.ui_top,
text="Send",
command=self.sendMsg)
self.ui_button_file = tkinter.Button(
master=self.ui_top,
text="File",
command=self.sendFile)
# Compute display position for all objects
self.ui_messages.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_input.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_button_send.pack(side=tkinter.LEFT)
self.ui_button_file.pack(side=tkinter.RIGHT)
# SEND button pressed
def sendMsg(self):
# Get user input (minus newline character at end)
msg = self.ui_input.get("0.0", tkinter.END+"-1c")
print("UI: Got text: '%s'" % msg)
# Add this data to the message window
self.ui_messages.insert(tkinter.INSERT, "%s\n" % (msg))
self.ui_messages.yview(tkinter.END) # Auto-scrolling
# Clean out input field for new data
self.ui_input.delete("0.0", tkinter.END)
# FILE button pressed
def sendFile(self):
file = askopenfilename()
if(len(file) > 0 and os.path.isfile(file)):
print("UI: Selected file: %s" % file)
else:
print("UI: File operation canceled")
# Event handler - User closed program via window manager or CTRL-C
def eventDeleteDisplay(self):
print("UI: Closing")
# Continuing closing window now
self.ui_top.destroy()
# Event handler - User clicked inside the "ui_input" field
def eventInputClick(self, event):
if(self.first_click):
# If this is the first time the user clicked,
# clear out the tutorial message currently in the box.
# Otherwise, ignore it.
self.ui_input.delete("0.0", tkinter.END)
self.first_click = False;
示例4: clientUI
# 需要导入模块: from tkinter.scrolledtext import ScrolledText [as 别名]
# 或者: from tkinter.scrolledtext.ScrolledText import yview [as 别名]
class clientUI():
def __init__(self, a_socket, a_username):
self.first_click = True;
self.a_socket = a_socket
self.a_username = a_username
def start(self):
print("Starting clientUI...")
self.initDisplay()
self.ui_messages.insert(tkinter.END, "Adding a message to the text field...\n")
self.ui_input.insert(tkinter.END, "<Enter message>")
def execute(self):
self.ui_top.mainloop() # This call to mainloop() is blocking and will last for the lifetime of the GUI.
print("Stopping clientUI...") # Should only get here after destroy() is called on ui_top
def initDisplay(self):
self.ui_top = tkinter.Tk()
self.ui_top.wm_title("GUI Demo")
self.ui_top.resizable('1','1')
self.ui_top.protocol("WM_DELETE_WINDOW", self.eventDeleteDisplay)
self.ui_messages = ScrolledText(
master=self.ui_top,
wrap=tkinter.WORD,
width=50, # In chars
height=25) # In chars
self.ui_input = tkinter.Text(
master=self.ui_top,
wrap=tkinter.WORD,
width=50,
height=4)
# Bind the button-1 click of the Entry to the handler
self.ui_input.bind('<Button-1>', self.eventInputClick)
self.ui_button_send = tkinter.Button(
master=self.ui_top,
text="Send",
command=self.sendMsg)
self.ui_button_file = tkinter.Button(
master=self.ui_top,
text="File",
command=self.sendFile)
# Compute display position for all objects
self.ui_messages.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_input.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_button_send.pack(side=tkinter.LEFT)
self.ui_button_file.pack(side=tkinter.RIGHT)
# SEND button pressed
def sendMsg(self):
# Get user input (minus newline character at end)
msg = self.a_username + ": " + self.ui_input.get("0.0", tkinter.END+"-1c")
msg_len = len(msg)
print("UI: Got text: '%s'" % msg)
print("Starting send thread . . .")
thread1 = sndThread(self.a_socket, self.a_username, msg_len, msg) #Launch sending Thread ###############################################################
thread1.daemon = True
thread1.start()
self.ui_messages.insert(tkinter.INSERT, "%s\n" % (msg)) # Add this data to the message window
self.ui_messages.yview(tkinter.END) # Auto-scrolling
# Clean out input field for new data
self.ui_input.delete("0.0", tkinter.END)
# FILE button pressed
def sendFile(self):
file = askopenfilename()
if(len(file) > 0 and os.path.isfile(file)):
print("UI: Selected file: %s" % file)
else:
print("UI: File operation canceled")
# Event handler - User closed program via window manager or CTRL-C
def eventDeleteDisplay(self):
leave_msg = "CHAT/1.0 LEAVE\r\nUsername: " + self.a_username + "\r\n\r\n"
try: #SEND
leave_raw_bytes = bytes(leave_msg,'ascii')
leave_bytes_sent = self.a_socket.sendall(leave_raw_bytes)
except socket.error as msg:
print("Error: send() failed\nDescription: " + str(msg))
sys.exit()
try: #CLOSE SOCKET
self.a_socket.close()
except socket.error as msg:
print("Error: unable to close() socket\nDescription: " + str(msg))
sys.exit()
#.........这里部分代码省略.........
示例5: clientUI
# 需要导入模块: from tkinter.scrolledtext import ScrolledText [as 别名]
# 或者: from tkinter.scrolledtext.ScrolledText import yview [as 别名]
class clientUI():
def __init__(self, args, q_send, q_receive_join, q_receive_text, q_receive_leave, b):
self.first_click = True;
self.args = args
self.q_send = q_send
self.q_receive_join = q_receive_join
self.q_receive_text = q_receive_text
self.q_receive_leave = q_receive_leave
self.b = b
def start(self):
print("Starting clientUI...")
self.initDisplay()
self.ui_messages.insert(tkinter.END, "%s has joined the chat room...\n" % self.args.username)
self.ui_input.insert(tkinter.END, "<Enter message>")
self.ui_top.after(100, self.receiveMsg)
# This call to mainloop() is blocking and will last for the lifetime
# of the GUI.
self.ui_top.mainloop()
# Should only get here after destroy() is called on ui_top
print("Stopping clientUI...")
def initDisplay(self):
self.ui_top = tkinter.Tk()
self.ui_top.wm_title("Chat Room 1.0 - %s" % self.args.username)
self.ui_top.resizable('1','1')
self.ui_top.protocol("WM_DELETE_WINDOW", self.eventDeleteDisplay)
self.ui_messages = ScrolledText(
master=self.ui_top,
wrap=tkinter.WORD,
width=50, # In chars
height=25) # In chars
self.ui_input = tkinter.Text(
master=self.ui_top,
wrap=tkinter.WORD,
width=50,
height=4)
# Bind the button-1 click of the Entry to the handler
self.ui_input.bind('<Button-1>', self.eventInputClick)
#self.ui_top.after(200, receiveMsg)
self.ui_button_send = tkinter.Button(
master=self.ui_top,
text="Send",
command=self.sendMsg)
# Compute display position for all objects
self.ui_messages.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_input.pack(side=tkinter.TOP, fill=tkinter.BOTH)
self.ui_button_send.pack(side=tkinter.LEFT)
# SEND button pressed
def sendMsg(self):
# Get user input (minus newline character at end)
msg = self.ui_input.get("0.0", tkinter.END+"-1c")
if len(msg) > 0:
self.q_send.put(msg)
print("UI: Got text: '%s'" % msg)
# Add this data to the message window
self.ui_messages.insert(tkinter.INSERT, "%s: %s\n" % (self.args.username, msg))
self.ui_messages.yview(tkinter.END) # Auto-scrolling
# Clean out input field for new data
self.ui_input.delete("0.0", tkinter.END)
# Receive messages from other clients
def receiveMsg(self):
#print ("Inside receiveMsg")
try:
username_join = self.q_receive_join.get(block=False)
join_msg = True;
except queue.Empty:
join_msg = False;
try:
username_text, text = self.q_receive_text.get(block=False)
text_msg = True;
except queue.Empty:
text_msg = False;
try:
username_leave = self.q_receive_leave.get(block=False)
leave_msg = True;
except queue.Empty:
leave_msg = False;
if join_msg:
self.ui_messages.insert(tkinter.INSERT, "%s has joined the chat room...\n" % username_join)
self.ui_messages.yview(tkinter.END) # Auto-scrolling
elif text_msg:
self.ui_messages.insert(tkinter.INSERT, "%s: %s\n" % (username_text, text))
#.........这里部分代码省略.........