Tkinter/Python - comboBox



我在应用程序中创建了一个 comboBox,但我不想在其中键入,只需选择其中一个选项即可。你可以帮我吗? 以下是下面的代码:

from tkinter import *
from tkinter import ttk

def new_window_cad_emp():
newWindow = Toplevel()
newWindow.geometry("800x600+275+75")
newWindow.resizable(height=False, width=False)
mylabel = LabelFrame(newWindow, text="")
mylabel.place(x=10, y=60, width=675, height=150)
l_codcad = Label(newWindow, text="  Código")
l_codcad.place(x=15, y=25)
e_codcad = Entry(newWindow)
e_codcad.place(x=75, y=25, width=40)
#<COMBOBOX>
l_tipcad = Label(newWindow, text="Tipo")
l_tipcad.place(x=500, y=100)
tipoPessoa = ttk.Combobox(newWindow,
values=[
"Pessoa Fisica",
"Pessoa Juridica"])
print(dict(tipoPessoa))
tipoPessoa.place(x=540, y=100, width=115)
tipoPessoa.current()
print(tipoPessoa.current(), tipoPessoa.get())
#</COMBOBOX>

bt = Button(newWindow, text="Novo")
bt.place(x=700, y=15, width=90, height=30)

试试这个:

tipoPessoa = ttk.Combobox(newWindow,values=["Pessoa Fisica","Pessoa Juridica"],state="readonly"(

最新更新