0

I am learning how to create and use GUI and i have been at this for the last 24 hours. I am sure its just a small problem but i have no one to ask around.

This is the code.I expected that when i run the code it will display the title and word on my GUI but its not displaying. I don't have any error messages and i don't know what to change anymore.

from tkinter import *

BACKGROUND_COLOR = "#B1DDC6"

window = Tk()
window.title("Flash Card")
window.config(padx=50, pady=50, bg=BACKGROUND_COLOR)

canvas = Canvas(width=800, height=526)
front_image = PhotoImage(file="images/card_front.png")
canvas.create_image(400, 263, image=front_image)
canvas.create_text(400, 150, text="Title", font=("Ariel", 40, "italic"))
canvas.create_text(200, 150, text="word", font=("Ariel", 40, "normal"))
canvas.config(bg=BACKGROUND_COLOR, highlightthickness=0)
canvas.grid(column=0, row=0, columnspan=2)

window.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Cannot reproduce the issue. I can see the "word" and "Title" text when running your code in my Windows 7 with Python 3.8.14. Does your image has a black background color so that the black text is not visible on a black background? – acw1668 Nov 21 '22 at 03:15
  • my image background color is white. on my end, i cannot see the "word" and "title" texts at all. – josephine omondi Nov 21 '22 at 03:22
  • The text appears fine for me on OSX. I see a greenish canvas with the text "word" and "Title", with "Title" in italics. – Bryan Oakley Nov 21 '22 at 03:32
  • Yes. That's exactly how its supposed to be. But I still can't see them on my OSX. – josephine omondi Nov 21 '22 at 03:49
  • why don't you try it running in a new virtual environment...? that may resolve the issue if there is any problem in your current setup. The code is running fine in my system as well ( kubuntu linux ) – Chrishdev Nov 21 '22 at 07:10
  • It might be under the image and not on the image. If you place your image away from the text, will you see the text or not? – 8349697 Nov 21 '22 at 16:04
  • You use "Ariel" als your font. Does this font really exist? I only know "Arial" ... – René Pöpperl May 24 '23 at 06:39
  • @josephine omondi. Ur code is working. I can see light green on background. – toyota Supra Sep 02 '23 at 09:52

3 Answers3

2

I also have MacBook Pro running Apple Silicon on Ventura 13.3.1(a) and I reproduce this issue. I fixed it by changing my display from "dark" mode on to dark mode off.

JoeT
  • 21
  • 2
0

Just a guess:

@JoeT says that it has something to do with darkmode. In darkmode the background is dark by default and the foreground (text) color is a light gray or white.

Perhaps the contrast between your chosen background color and the default text color (white?) is too low, to see the text.

Try setting the foreground / text color explicitly to a darker color, that provides good contrast.

René Pöpperl
  • 567
  • 5
  • 18
0

You can add another argument into create_text method to update text color. Probably it returns white automatically. fill argument helps you to make visible your text.

canvas.create_text(400, 150, text="Title", font=("Ariel", 40, "italic", fill='black'))

Gamze
  • 1
  • 2
  • On `Python3.12.0tc`1 got an error...saying that do you meant `'=='` or `':='` instead of `'='` – toyota Supra Sep 02 '23 at 09:48
  • Could you please share the complete error message? It works for Python 3.10. Maybe, there are some differences in 3.12. Also, [docs](https://docs.python.org/3.12/whatsnew/3.12.html) can be reviewed for the issue: – Gamze Sep 02 '23 at 19:02