user2983638
user2983638

Reputation: 941

How to anchor figures to the Entry Widget in Tkinter (Python)?

On the internet I have found this piece of code that builds a simple graphical interface:

from Tkinter import *


fields = 'Last Name', 'First Name', 'Job', 'Country'



def fetch(entries):
   for entry in entries:
      field = entry[0]
      text  = entry[1].get()
      print('%s: "%s"' % (field, text))


def makeform(root, fields):
   entries = []
   for field in fields:
      row = Frame(root)
      lab = Label(row, width=15, text=field, anchor='w')
      ent = Entry(row)
      row.pack(side=TOP, fill=X, padx=5, pady=5)
      lab.pack(side=LEFT)
      ent.pack(side=RIGHT, expand=YES, fill=X)
      entries.append((field, ent))
   return entries

if __name__ == '__main__':

   root = Tk()
   ents = makeform(root, fields)
   root.bind('<Return>', (lambda event, e=ents: fetch(e)))

   b1 = Button(root, text='Show', command=(lambda e=ents: fetch(e)))
   b1.pack(side=LEFT, padx=5, pady=5)

   b2 = Button(root, text='Quit', command=root.quit)
   b2.pack(side=LEFT, padx=5, pady=5)

   root.mainloop()

Since tkinter does not support latex symbols, I would like to "replace" the strings in fields with small pictures that represent the mathematical symbols I need. Moreover, I would like to have a minimal software, so I need to use only tkinter functions. I've spent two hours trying to figure out how to do it with PhotoImage, but I'm not able to do what I want. Do you know any intelligent method to solve this problem? Many thanks in advance!

Upvotes: 0

Views: 1796

Answers (2)

user2983638
user2983638

Reputation: 941

Thanks to everyone. At the end I solved the problem by using

root = Tk()
my_image = PhotoImage(data="Figure.gif")
Label(root, image=my_image)

Upvotes: 0

TigerhawkT3
TigerhawkT3

Reputation: 49310

I would recommend using a Text widget. You can then insert images with image_create.

Upvotes: 1

Related Questions