tkinter 在消息框中显示输出

tkinter display output in message box

我想显示我查询的条目的结果。我设法在控制台中显示了结果,但没有显示 tkMessageBox.showinfo 打开的消息。 相反,我得到了一些数值。这很奇怪,因为

下面是我的代码。

    #!/usr/bin/env python
from Tkinter import *
import tkSimpleDialog
import tkMessageBox
import time
import requests
def show_entry_fields():
print("loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n " % (ChamploginS3.get(), ChampsecretpasseS3.get(), ChampsendpointS3.get()))
ChamploginS3.delete(0,END)
ChampsecretpasseS3.delete(0,END)
ChampsendpointS3.delete(0,END)
tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %( ChamploginS3,ChampsecretpasseS3,ChampsendpointS3))
fenetre0 = Tk()
fenetre0.title('S3 brower perso')
fenetre0.geometry("380x100")
Label1 = Label(fenetre0, text = 'loginS3', fg = 'blue').grid (row=0)
Label2 = Label(fenetre0, text = 'secretpasseS3', fg = 'red').grid (row=1)
Label3 = Label(fenetre0, text = 'endpointS3', fg = 'purple').grid (row=2)
loginS3= StringVar()
ChamploginS3 = Entry(fenetre0, textvariable= loginS3, bg ='bisque', fg='maroon')
secretpasseS3= StringVar()
ChampsecretpasseS3 = Entry(fenetre0, textvariable= secretpasseS3, show='*', bg ='bisque', fg='maroon')
endpointS3= StringVar()
ChampsendpointS3 = Entry(fenetre0, textvariable= endpointS3, bg ='bisque', fg='maroon')
ChamploginS3.grid(row=0, column=1)
ChampsecretpasseS3.grid(row=1, column=1)
ChampsendpointS3.grid(row=2, column=1)
Bouton1 = Button(fenetre0, text = 'END', command = fenetre0.destroy).grid(row=3, column=0, sticky=W, pady=4)
Bouton2 = Button(fenetre0, text = 'SHOW', command = show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
fenetre0.mainloop()

您需要解决 2 件事:

首先,不要删除那些条目的内容。这意味着你必须删除这 3 行

  ChamploginS3.delete(0,END)
  ChampsecretpasseS3.delete(0,END)
  ChampsendpointS3.delete(0,END)

其次,使用 get() 方法访问条目小部件的内容。这意味着您需要更改此行:

tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %( ChamploginS3,ChampsecretpasseS3,ChampsendpointS3))

收件人:

tkMessageBox.showinfo (title='inputs for S3', message="are those inputs correct ? " '\n' 'loginS3: %s \n secretpasseS3: %s \n endpointS3: %s \n ' %(ChamploginS3.get(),ChampsecretpasseS3.get(),ChampsendpointS3.get()))

演示:

完成上述操作后,您将得到您期望的结果: