Search code examples
pythontkintermessageboxdisplay

tkinter display output in message box


I would like to display the result of the entry that I asked. I managed to display result in the console but not the message opened by tkMessageBox.showinfo. Instead I get sme numerical values. which is quite strange since

Below is my code.

    #!/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()

Solution

  • There are 2 things you need to fix:

    First of all, do not delete the content of those entries. This means you must remove away these 3 lines:

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

    Secondly, the content of an entry widget is accessed using the get() method. This means you need to change this line:

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

    To:

    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()))
    

    Demo:

    After doing what mentioned above, you will get what you expect:

    enter image description here