|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from tkinter import *
- root=Tk()
- root.geometry("563x543")
- a=[
- {"name":"覆盖","relief":"sunken"},
- {"name":"天空","relief":"raised"}]
- for i in range (len(a)) :
- b=Button(root,
- text=a["name"],
- relief=a["relief"],
- borderwidth=9,
- width=11,
- height=3,
- justify="left",
- wraplength=222,
- font="汉仪哈哈体简 20 italic")
- b.pack(expand=True)
- mainloop()
复制代码
问 题 出 在 第 9 句 和 第 1 0 句 , 应 该 如 何 修 改 ?
本帖最后由 liuhongrun2022 于 2024-3-2 09:26 编辑
关于字体的那一行,我没有这个字体,请自行添加
- from tkinter import *
- root = Tk()
- root.geometry("563x543")
- a = [
- {"name": "覆盖", "relief": "sunken"},
- {"name": "天空", "relief": "raised"}
- ]
- for i in range(len(a)):
- b = Button(root,
- text=a[i]["name"], # 列表里应该先有索引,然后是字典里的键值对
- relief=a[i]["relief"],
- borderwidth=9,
- width=11,
- height=3,
- justify="left",
- wraplength=222,
- )
- b.pack(expand=True)
- mainloop()
复制代码
或者
- from tkinter import *
- root = Tk()
- root.geometry("563x543")
- a = [
- {"name": "覆盖", "relief": "sunken"},
- {"name": "天空", "relief": "raised"}
- ]
- for i in a: # 直接遍历列表
- b = Button(root,
- text=i["name"],
- relief=i["relief"],
- borderwidth=9,
- width=11,
- height=3,
- justify="left",
- wraplength=222,
- )
- b.pack(expand=True)
- mainloop()
复制代码
求个最佳答案
|
|