0

I was practicing tkinter in python 3.6 using spyder IDE on Ubuntu 18.04 LTS. I am having issues with it like:

1. I am not able add Text widget.

# text area
textarea1 = ttk.Text(win).pack()

Output

AttributeError: module 'tkinter.ttk' has no attribute 'Text'

2.When I try to add image to the label it throws error but sometimes it doesn't on the same code.

logo = PhotoImage(file = "images/whiteFlames.png")
small_logo = logo.subsample(5,5)

label1 = ttk.Label(win, text = "Hi there,", image = small_logo)
label1.pack()

Output

TclError: image "pyimage36" doesn't exist

3.Same thing like the label happened with the buttons too it works and doesn't work on the same code.

I tried to pip install tkinter (in terminal) to ensure that it gets reinstalled if the issue was with installation but the output was:

Collecting tkinter
  Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter

4.I can't change the font and the text is also looking weird too.

Font not changing issue

from tkinter import *
from tkinter import ttk
import tkinter.font as font
win = Tk()
win.title("Bit Coin Trader")
win.config(bg = "grey")
win.geometry("300x300")
# section 1
shareLabel = ttk.Label(win, text = "Target Price($):")
shareLabel.config(background = 'grey', foreground = 'white', font = font.Font(family='Times'))
shareLabel.grid(row = 0, column = 0, sticky = 'W')

targetLabel = ttk.Label(win, text = "Target Price($):")
targetLabel.config(background = 'grey', foreground = 'white', font = font.Font(family='Arial'))
targetLabel.grid(row = 1, column = 0, sticky = 'W')
win.mainloop()

Please help me with this!

Minimal code for image issue

from tkinter import *
from tkinter import ttk

win = Tk()

win.title("widgets")

# setting a size of 400x400 px
win.geometry("400x200")


logo = PhotoImage(file = "images/whiteFlames.png")
small_logo = logo.subsample(5,5)

label1 = ttk.Label(win, text = "Hi there,",image = small_logo)
label1.pack()

button1 = ttk.Button(win, text = "Click Me",image = small_logo)
button1.pack()
button1.config(command = onClick) # this adds action to button

win.mainloop()

But this is working now...don't know the exact reason but its working after I updated my python 3.6.7 to 3.6.8

Star Rider
  • 389
  • 2
  • 15
  • Tkinter is no a pip package but comes installed with python. You could try repairing your python install or uninstalling and reinstalling python. – Tim Jan 12 '19 at 13:16
  • I did conda install python=3.6 then it updated to python 3.6.8 and things are working(issue 2 and 3 solved). For issue 1 I replaced ttk.Text------> Text and it solved my problem. thanks Tim for idea! – Star Rider Jan 12 '19 at 15:16
  • ttk dosn't have a text widget; the text widget is in the tkinter module. As for the image question, there's not enough detail for us to give a proper answer. Please provide a [mcve]. Finally, you can't install tkinter with pip. – Bryan Oakley Jan 12 '19 at 15:49
  • The font issue is solved [here](https://stackoverflow.com/questions/47769187/make-anacondas-tkinter-aware-of-system-fonts-or-install-new-fonts-for-anaconda) – Star Rider Jan 15 '19 at 12:17

0 Answers0