簡體   English   中英

在同一打開的窗口中的python打印命令不在提示符下

[英]python print command in same open window not in prompt

好的,所以我嘗試使用python並遇到我試圖組合的這個小應用程序的問題。 我試圖在運行時打開一個窗口,並要求輸入關鍵字,然后將該輸入與文件中的任何行匹配。 我輸入了輸入並按顯示,但結果未顯示或未在提示中顯示。 我需要在打開的窗口中顯示結果。 可能在按下顯示按鈕時創建的新行和新列上。 因此結果僅顯示在窗口中,我在基於ubuntu的系統上。 這是我的應用程序.py文件

#!/usr/bin/python
# -*- coding: utf-8 -*-

# sets the name settings
from Tkinter import *
class App(Frame):
def __init__(self, master=None):
    Frame.__init__(self, master)
    self.pack()

# runs the script to get full 
# list of programs for matching
#subprocess.call(["listcmnd.sh"])

# create the application
myapp = App()

# sets the e1 variable
e1 = Entry(myapp)

# checks keyword agianst 
# programs in the sam.txt file
import re

keyword = open("results/program_files/sam.txt", "r")

for line in keyword:
if re.match("str(text)", line):
    print line,

# prints results of keyword entry match
def show_entry_fields():
print("Program Name: %s" % (e1.get()))

# gives the output of findings
from Tkinter import *

# asks for search critiria
text = Label(myapp, text="Keyword: ").grid(row=0)

# displays the buttons for getting 
# results and closing program
Button(myapp, text='Quit', command=myapp.quit).grid(row=3, column=0,     sticky=W, pady=4)
Button(myapp, text='Show', command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)

# prints results of keyword entry match
def show_entry_fields():
print("Program Name: %s" % (e1.get()))

# displays the text entry field
e1.grid(row=0, column=1)

#
# here are method calls to the window manager class
#
myapp.master.title("Program Search Tool")
myapp.master.maxsize(1000, 400)

# start the program
myapp.mainloop()

好的,所以我對主腳本進行了一些更改,但仍將結果輸出到終端,而不是在打開的窗口中

這是新的代碼更改

  #!/usr/bin/python
  # -*- coding: utf-8 -*-

  # sets the name settings
  from Tkinter import *
  class App(Frame):
      def __init__(self, master=None):
         Frame.__init__(self, master)
          self.pack()

  # runs the script to get full 
  # list of programs for matching
  #subprocess.call(["listcmnd.sh"])

  # create the application
  myapp = App()

  # sets the e1 variable
  e1 = Entry(myapp)

  # checks keyword agianst 
  # programs in the sam.txt file
  import re

  keyword = open("results/program_files/sam.txt", "r")

  for line in keyword:
    if re.match("get()(text)", line):
          print line,

  # prints results of keyword entry match
  def show_entry_fields():
    print("Program Name: %s" % (e1.get()))

  # asks for search critiria
  # displays the text entry field
  e1.grid(row=0, column=1)
  text = Label(myapp, text="Program Name: ")
  text.grid(row=3, column=0)

  # displays the buttons for getting 
  # results and closing program
  Button(myapp, text='Quit', command=myapp.quit).grid(row=4, column=0, sticky=W, pady=4)
  Button(myapp, text='Show', command=show_entry_fields).grid(row=2, column=0, sticky=W, pady=4)

  #
  # here are method calls to the window manager class
  #
  myapp.master.title("Program Search Tool")
  myapp.master.maxsize(1000, 1000)
  myapp.master.minsize(50, 50)

  # start the program
  myapp.mainloop()

您應該做的是在函數中創建一個標簽(或者可能在之前創建並更新它)

def show_entry_fields():

附加說明:

您多次導入Tkinter

您還定義了def show_entry_fields():兩次

text = Label(myapp, text="Keyword: ").grid(row=0)

不起作用。 您必須寫:

 text = Label(myapp, text="Keyword: ")
 text.grid(row=0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM