python获取当前控件名_python如何获取tkinter组件的名称?比如按下多个Button中的一个,返回这个被按下的Button的text?...

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70import tkinter as tk

window = tk.Tk()

window.title('计算器')

window.geometry('360x435')

window.attributes("-alpha", 0.95)

window.resizable(0, 0)#窗口大小固定,不能缩放

var = tk.StringVar()

frm_1 = tk.Frame(window, width=360, height=115, bg='CadetBlue').place(x=0, y=0, anchor=tk.NW)#数字显示区

frm_2 = tk.Frame(window, width=270, height=240, bg='DarkSeaGreen').place(x=0, y=115, anchor=tk.NW)#数字键盘

frm_3 = tk.Frame(window, width=90, height=320, bg='Beige').place(x=270, y=115, anchor=tk.NW)#加减乘除

frm_4 = tk.Frame(window, width=270, height=80, bg='CadetBlue').place(x=0, y=355, anchor=tk.NW)#不可循环输出的

var_result = tk.StringVar()

var_dian=tk.StringVar()

var_dian.set('.')

def name(u):

u='var'+str(u)

return u

#数字显示区

I = tk.Entry(frm_1,textvariable=var_result,font=('Arial',40),bg='grey')

I.place(x=0,y=0,width=360,height=115)

#获取数字显示区的文字

#函数部分

#计算结果的

def show_result():

result = I.get()

print(eval(result))

def delete():

f.delete(1.0, tk.END)

def get():

pass

num=1

#数字键盘,可循环显示的

for j in range(3):

for i in range(3):

m=0+(i)*90

n=115+(j)*80

b=tk.Button(frm_2,text=num,bg='WhiteSmoke',font=('Arial','20'),command=get)

b.place(x=m,y=n,width=90,height=80)

num=num+1

#数字键盘,不可循环显示的

v=0

a=tk.Button(frm_4,textvariable=var_dian,bg='Gainsboro',font=('20')).place(x=0,y=355,width=90,height=80)

b=tk.Button(frm_4,text='=',bg='Gainsboro',font=('20'),command=show_result).place(x=180,y=355,width=90,height=80)

f=tk.Button(frm_4,text='0',bg='WhiteSmoke',font=('Arial','20')).place(x=90,y=355,width=90,height=80)

#加减乘除

q=0

for p in ['+','-','*','/']:

e=tk.Button(frm_3,text=p,bg='Gainsboro',font=('20')).place(x=270,y=115+q*80,width=90,height=80)

q=q+1

window.mainloop()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值