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.
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