Py学习  »  Python

将python日历插入tkinter标签

jim leahy • 4 年前 • 546 次点击  

我写的代码有问题。当我插入变量时 calendar2019 进入Tkinter标签 LabelCalen 它不会出现在窗口 root4 ,和窗口 根4 一点都没有。

import calendar
import tkinter as tk

def CalScr():
    calendar2019 = calendar.calendar(2019)#creating calender variable
    root4 = tk.Tk()
    labelCalen= tk.Label(root4, text = calendar2019, )
    root4.mainloop
CalScr()

压延机应该印在标签上 拉贝尔

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44042
 
546 次点击  
文章 [ 1 ]  |  最新文章 4 年前
martineau
Reply   •   1 楼
martineau    5 年前

问题之一是您没有调用 mainloop 因为你忽略了 () . 另一个是你没有给标签一个位置。

#! /usr/bin/env python
import calendar
import tkinter as tk
def CalScr():
    calendar2019 = calendar.calendar(2019) #creating calender variable
    root4 = tk.Tk()
    labelCalen= tk.Label(root4, text = calendar2019, font=("Courier New", 14))
    labelCalen.grid(column=0, row=0)
    root4.mainloop()
CalScr()

这也将字体设置为固定间距,否则日历将无法正确对齐。