forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtklabelimage.py
More file actions
executable file
·34 lines (26 loc) · 1.01 KB
/
tklabelimage.py
File metadata and controls
executable file
·34 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import sys, os
# TkInter changed its capitalization between Python versions. Sigh.
if sys.version[:1] == '2':
import Tkinter as tk
else:
import tkinter as tk
# Requires: python3-pil.imagetk or python-pil.imagetk
from PIL import ImageTk, Image
imgpath = os.path.expanduser("~/Images/Icons/tux/tux.gif")
labeltxt = """Here is a whole bunch of text.
It has multiple lines in it. It's like a paragraph, almost,
except that it doesn't have anything useful to say."""
class View(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.image = ImageTk.PhotoImage(Image.open(imgpath))
# The compound= controls where the image is drawn relative to the text.
b = tk.Label(self, text=labeltxt, image=self.image,
justify="left", compound="left")
b.pack(side="top")
if __name__ == "__main__":
root = tk.Tk()
view = View(root)
view.pack(side="top", fill="both", expand=True)
root.mainloop()