python中组合框_python – 如何控制tkinter组合框选择突出显示

本文介绍了一个Python GUI应用程序,用于法拉单位转换。作者在使用tkinter的ttk.Combobox时遇到一个问题,即无法控制组合框选择项的高亮显示。他们希望去除或调整这个高亮效果,但目前只能改变组合框的背景颜色。代码示例展示了如何创建和绑定事件以进行转换计算,但未提供解决高亮问题的具体解决方案。
摘要由CSDN通过智能技术生成

我写了一个小法拉转换器来学习GUI编程.它很棒,看起来很精致.唯一的问题是我似乎无法弄清楚如何控制我的ttk.Combobox选择出现的这个奇怪的突出显示.我确实使用了ttk.Style(),但它只改变了ttk.Combobox背景,条目等的颜色.我也尝试改变openbox / gtk主题.

我在谈论文章“microfarads(uF)”中的内容.

如果突出显示整个盒子,那就没关系了.但我宁愿让它完全消失.

我怎样才能操纵ttk.Combobox的选择亮点?

# what the farad?

# thomas kirkpatrick (jtkiv)

from tkinter import *

from tkinter import ttk

# ze la programma.

def conversion(*args):

# this is the numerical value

inV = float(inValue.get())

# these two are the unit (farads, microfarads, etc.) values

inU = inUnitsValue.current()

outU = outUnitsValue.current()

# "mltplr" is multiplied times inValue (inV)

if inU == outU:

mltplr = 1

else:

mltplr = 10**((outU - inU)*3)

outValue.set(inV*mltplr)

# start of GUI code

root = Tk()

root.title("What the Farad?")

# frame

mainFrame = ttk.Frame(root, width="364", padding="4 4 8 8")

mainFrame.grid(column=0, row=0)

# input entry

inValue = StringVar()

inValueEntry = ttk.Entry(mainFrame, width="20", justify="right", textvariable=inValue)

inValueEntry.grid(column=1, row=1, sticky="W")

# input unit combobox

inUnitsValue = ttk.Combobox(mainFrame)

inUnitsValue['values'] = ('kilofarads (kF)', 'farads (F)', 'millifarads (mF)', 'microfarads (uF)', 'nanofarads (nF)', 'picofarads (pF)')

inUnitsValue.grid(column=2, row=1, sticky="e")

inUnitsValue.state(['readonly'])

inUnitsValue.bind('<>', conversion)

# result label

outValue = StringVar()

resultLabel = ttk.Label(mainFrame, textvariable=outValue)

resultLabel.grid(column=1, row=2, sticky="e")

# output unit combobox

outUnitsValue = ttk.Combobox(mainFrame)

outUnitsValue['values'] = ('kilofarads (kF)', 'farads (F)', 'millifarads (mF)', 'microfarads (uF)', 'nanofarads (nF)', 'picofarads (pF)')

outUnitsValue.grid(column=2, row=2, sticky="e")

outUnitsValue.state(['readonly'])

outUnitsValue.bind('<>', conversion)

# padding for widgets

for child in mainFrame.winfo_children(): child.grid_configure(padx=4, pady=4)

# focus

inValueEntry.focus()

# bind keys to convert (auto-update, no button)

root.bind('', conversion)

root.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值