小编esp*_*tro的帖子

如何阻止 Tkinter 消息小部件调整大小?

我正在创建三个“消息小部件”,但它们似乎根据内部内容调整宽度和高度的大小,是否可以防止这种情况?

from tkinter import *

root = Tk()
root.configure(background = 'Yellow')
root.geometry('500x400')

a = '{}'.format('The Elepthan is Big')
b = '{}'.format('The Bird')
c = '{}'.format('The Lion is big and ferocious, kills any animal')

msg = Message(root, text = a, width=300, justify='left')
msg.config(bg='lightgreen',relief=RIDGE, font=('times', 9), pady=-2, borderwidth=3)
msg.pack()


msg = Message(root, text = b, width=300, justify='left')
msg.config(bg='lightgreen',relief=RIDGE, font=('times', 9), pady=-2, borderwidth=3)
msg.pack()

msg = Message(root, text = c, width=300, justify='left')
msg.config(bg='lightgreen',relief=RIDGE, font=('times', 9), pady=-2, borderwidth=3)
msg.pack()




root.mainloop()
Run Code Online (Sandbox Code Playgroud)

python tkinter

5
推荐指数
1
解决办法
2917
查看次数

在python中拆分字符串以获取一个值?

需要帮助,让我们假设我在一个名为'input'的变量中有一个字符串'Sam-Person'

name, kind = input.split('-')
Run Code Online (Sandbox Code Playgroud)

通过以上操作,我得到两个变量,其中不同的字符串'Sam'和'Person'有一种方法只能得到第一个值name ='Sam',而不需要额外的变量'kind'而无需使用名单?这样做时,假设我只会得到'Sam':

name = input.split('-')
Run Code Online (Sandbox Code Playgroud)

我得到一个列表,然后我可以通过索引名[0]或名称[1]访问这些值,但这不是我想要的,我只是想直接将'Sam'变成变量'name',是吗一种方法可以做到这一点或替代分裂?

python string list

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

list ×1

string ×1

tkinter ×1