Tkinter按钮样式(浮雕)无法正确显示 [英] Tkinter Button style (relief) not showing properly

查看:53
本文介绍了Tkinter按钮样式(浮雕)无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在tkinter中创建按钮时,我尝试使用救济"选项,但是按钮的样式无法正确显示.

I tried to use "relief" option when creating buttons in tkinter, but the style of buttons are not showing properly.

这是我找到的信息网站的链接.该网站上有预期结果的图片. https://www.tutorialspoint.com/python/tk_relief.htm

Here is a link to the website of info I found. There is a picture of expected result on that website. https://www.tutorialspoint.com/python/tk_relief.htm

我的代码:

from tkinter import *
# from tkinter.ttk import *


root = Tk()
root_width, root_height = 200, 500
root.geometry("{}x{}".format(root_width, root_height))

b1 = Button(root, text="button", relief=FLAT)
b2 = Button(root, text="button", relief=RAISED)
b3 = Button(root, text="button", relief=SUNKEN)
b4 = Button(root, text="button", relief=GROOVE)
b5 = Button(root, text="button", relief=RIDGE)

b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()

root.mainloop()

出现在屏幕上的所有按钮看起来完全一样.我的结果

All the buttons appear on the screen look exactly the same. my result

想知道为什么会发生这种情况,有没有办法我可以修复它,或者有其他方法可以让我自定义按钮小部件.

Wondering why this happens, is there a way I can fix it or other methods that allow me to customize the button widget.

我尝试使用ttk,但是发生以下错误

I tried to use ttk, but the following error occurred

_tkinter.TclError: unknown option "-relief"

我目前在装有macOS Sierra 10.12的MacBook Pro上的PyCharm中运行Python3.

I am currently running Python3, in PyCharm, on MacBook Pro with macOS Sierra 10.12 installed.

谢谢!

推荐答案

您正在OSX上运行,并且该OS对于按钮的外观具有严格的指导原则.您无法更改OSX上按钮的释放方式.

You are running on OSX, and that OS has strict guidelines for the appearance of buttons. You can't change the relief on buttons on OSX.

这篇关于Tkinter按钮样式(浮雕)无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆