在文本框中显示所有“print()”。特金特Python

2024-09-28 03:20:36 发布

您现在位置:Python中文网/ 问答频道 /正文

在开始时,我有空的文本框。我需要在我的文本框中显示所有打印信息 任何信息都应该显示在里面 例如:

from Tkinter import *
import ttk
import tkFileDialog

DEBUG = True

class MainRB():
  def __init__(self, *args, **kwargs):
    self.root = Tk()
    self.root.minsize(height = 550, width = 1200)
    self.root.maxsize(height = 550, width = 1200)

    #################
    self.panelFrame3 = Frame(self.root, height = 45, width = 1200, bg = 'black')

    self.panelFrame1 = Frame(self.root, height = 45, width = 800, bg = 'green')
    self.textFrame1 = Frame(self.root, height = 600, width = 800, bg = 'red')

    ###################
    self.panelFrame3.place(x=1, y=1)

    self.panelFrame1.place(x=1, y=47)
    self.textFrame1.place(x=1, y=93)


    #################
    self.textbox1 = Text(self.textFrame1, height = 20, width = 70, font='Arial 14', wrap='word')
    self.scrollbar1 = Scrollbar(self.textFrame1)

  #####################
    self.scrollbar1['command'] = self.textbox1.yview
    self.textbox1['yscrollcommand'] = self.scrollbar1.set


    ######################
    self.textbox1.pack(side = 'left', fill = 'both', expand = 1)
    self.scrollbar1.pack(side = 'right', fill = 'y')

    ########################
    self.logBtn = ttk.Button(self.panelFrame3, text = "test")
    self.quitBtn = ttk.Button(self.panelFrame3, text = 'Quit')

    ########################

    self.quitBtn.bind("<Button-1>", self.Quit)
    self.logBtn.bind("<Button-1>", self.PushLog)

    self.logBtn.place(x = 230, y = 10, width = 50, height = 25)
    self.quitBtn.place(x = 1088, y = 10, width = 100, height = 25)
    self.root.mainloop()


  def PushLog(self, ev):
      print "111111"



  def Quit(self, ev):
      if serial.isOpen() == True:
          serial.close()
          print(serial.portstr + " is disconnect.")
      print "Bye."
      self.root.destroy()

if __name__ == "__main__":
    app = MainRB()

当我按下[logBtn]按钮时,需要在我的文本框的第一个字符串中显示-“111111”。你知道吗


Tags: importselfdefplacebuttonrootwidthttk

热门问题