tkinter代理在python 3.6上很奇怪

时间:2019-01-12 13:06:22

标签: python python-3.x tkinter

我在Ubuntu 18.04 LTS上使用spyder IDE在python 3.6中练习tkinter。我遇到了类似的问题:

1。我无法添加文本小部件。

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

输出

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

2。当我尝试将图像添加到标签时,它会引发错误,但有时它不在同一代码上。

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

3。与标签类似的事情也发生在按钮上,它也可以工作,并且不适用于同一代码。

我试图通过pip install tkinter(在终端中)来确保如果问题是由于安装而导致的,但输出是:

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

4。我无法更改字体,文本也看起来很奇怪。

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()

请帮助我!

发布图像的最小代码

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之后工作了

0 个答案:

没有答案