Tkinter TEXT background image - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Tkinter TEXT background image (/thread-30687.html) |
Tkinter TEXT background image - _ShevaKadu - Nov-01-2020 Hey there! I'm making a program manager with Tkinter and I want to set the background image of the Text widget which contains the buttons to an image. Here is the code: from tkinter import * import os def command(d): print(d) a = Tk() scroll = Scrollbar(a, orient="vertical") text = Text(a, width=20, height=15, wrap="none", yscrollcommand=scroll.set) scroll.place(x=0, y=0, height=270, anchor='nw') text.place(x=15, y=0, anchor='nw') scroll.configure(command=text.yview) b = [] c = [] DEBUG = {} DEBUG['random'] = ['hhwher', 'fgiwue', 'ewhrgj', 'wrejkh', 'fkhejw', 'qhkwje', 'hsajkd', 'asjkdh', 'haksdj', 'hadjsg', 'kdjsha', 'hkadjs', 'rweyiu', 'jdkhsa'] for x in range(len(os.listdir())): if os.path.isfile(os.listdir()[x]): b.append(os.listdir()[x]) if os.path.isdir(os.listdir()[x]): c.append(os.listdir()[x]) b = DEBUG['random'] for x in b: x = Button(text, text=x, anchor='e', bg='black', font=('DIN Alternate', '15'), width=15, command=lambda j=x: command(j)) text.window_create("end", window=x) text.insert("end", "\n") text.configure(state=DISABLED) a.mainloop()(You can remove all the code containing the DEBUG variable.) Output: I hope you can understand what I mean, thanks for all the help! RE: Tkinter TEXT background image - joe_momma - Nov-01-2020 I don't understand- do you want a background image overlaid by the buttons or insert the image with the buttons? I don't the text widget is a great candidate for the first option, maybe a scrolled canvas with an image and buttons placed over. the second try: from PIL import Image, ImageTk a = Tk() img = Image.open("example.png") image_ = ImageTk.PhotoImage(img) scroll = Scrollbar(a, orient="vertical") text = Text(a, width=25, height=15, wrap="none", yscrollcommand=scroll.set) text.image_create("1.0", image=image_) RE: Tkinter TEXT background image - deanhystad - Nov-01-2020 It is strange because the OP is using a Text object where sane people use a frame on a canvas. So in his app the background for the buttons is a text object. Interesting. This talks a little about styles for a Text object. https://effbot.org/tkinterbook/text.htm I don't know if background image is supported. You could try bgstipple and see if that works for you. RE: Tkinter TEXT background image - _ShevaKadu - Nov-02-2020 ignore this post RE: Tkinter TEXT background image - _ShevaKadu - Nov-02-2020 (Nov-01-2020, 09:35 PM)joe_momma Wrote: I don't understand- do you want a background image overlaid by the buttons or insert the image with the buttons? I don't the text widget is a great candidate for the first option, maybe a scrolled canvas with an image and buttons placed over.how do I make a scrollable canvas then? RE: Tkinter TEXT background image - joe_momma - Nov-02-2020 scrolled canvas and canvas create_image |