打印使用Python的信息?

huangapple go评论90阅读模式
英文:

Printing out information with python?

问题

我尝试将信息打印到这个窗口而不是控制台。我该如何做?

  1. from tkinter import *
  2. print("Hello")
  3. gui = Tk(className='StreetView Map')
  4. # 设置窗口大小
  5. gui.geometry("500x200")
  6. gui.mainloop()

我尝试使用print函数,但窗口中没有显示任何内容。

英文:

I'm trying to print out information into this window and not in the console. How do I do this?

  1. from tkinter import *
  2. print("Hello")
  3. gui = Tk(className='StreetView Map')
  4. # set window size
  5. gui.geometry("500x200")
  6. gui.mainloop()

I tried using the print function but nothing showed up in the window.

答案1

得分: 1

你可以创建一个 Label

  1. Label(gui, text="Hello").pack()
英文:

You can create a Label.

  1. Label(gui, text="Hello").pack()

答案2

得分: 0

以下是您要的代码的中文翻译:

  1. # 创建一个文本小部件,可以在Tkinter GUI上插入文本。
  2. from tkinter import *
  3. # 创建一个GUI窗口
  4. gui = Tk(className='StreetView Map')
  5. # 设置窗口大小
  6. gui.geometry("500x200")
  7. # 创建一个文本小部件
  8. T = Text(gui, height=5, width=52)
  9. T.pack()
  10. # 在文本小部件中插入字符串
  11. T.insert(END, "你好")
  12. # 运行GUI主循环
  13. gui.mainloop()
英文:

You need to Create a Text widget where you can insert the test on GUI on Tkinter.

Given your code it would have to be done like this.

  1. from tkinter import *
  2. gui = Tk(className='StreetView Map')
  3. # set window size
  4. gui.geometry("500x200")
  5. T = Text(root, height = 5, width = 52)
  6. T.pack()
  7. #insert the string in Text Widget
  8. T.insert(tk.END, "hello")
  9. gui.mainloop()

huangapple
  • 本文由 发表于 2023年2月19日 12:15:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497951.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定