我在Ubuntu 18.04 LTS上使用spyder IDE在python 3.6中练习tkinter。我遇到了类似的问题:
# text area
textarea1 = ttk.Text(win).pack()
输出
AttributeError: module 'tkinter.ttk' has no attribute 'Text'
logo = PhotoImage(file = "images/whiteFlames.png")
small_logo = logo.subsample(5,5)
label1 = ttk.Label(win, text = "Hi there,", image = small_logo)
label1.pack()
输出
TclError: image "pyimage36" doesn't exist
我试图通过pip install tkinter(在终端中)来确保如果问题是由于安装而导致的,但输出是:
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
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()
请帮助我!
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()
但是这现在正在工作...不知道确切的原因,但是在我将python 3.6.7更新为3.6.8之后工作了