基础17·硕士往年试题下载软件开发(tkinter下的url打开,光标显示)


from tkinter import *
import webbrowser as wb


def main():

    texts = {"长沙理工大学":
        (
       "2015年硕士研究生初试试题","2015年硕士研究生复试试题",
        "2016年硕士研究生初试试题","2016年硕士研究生复试试题",
        "2017年硕士研究生初试试题", "2017年硕士研究生复试试题",
        "2018年硕士研究生初试试题","2018年硕士研究生复试试题",
        )
            }
    def click1(a):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=NkIyN0YxNThFMjNGREJDQTFDMTQ1NjA5NEYzQTQ3QjUvMThCRDQ1M0EvQzhDOTlE")

    def click3(b):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=NDVDMzBCM0YyNENDNTgwMjYzREI1QjlENTI2NkU2OTIvQjQ0NjgyQ0IvNkEwOEYz")

    def click5(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=MTc4MUYzNzEwM0QzMjdDNUY3RDlEMzMxQjQ2NzdGNkUvNjhCRjE5RjUvQ0EyODhG")

    def click7(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=MjJCRkFGRkFGRTUxQzYzMTc2OUQ0QjE0MjhDNTBFNUIvNUNEODI5OEQvNzA1REUz")

    def click9(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=NEE1OTUwQ0RFQzc4M0REMTU1RkYyQzk1MkVGNjY1RjEvODdBQzE5NDIvQzg1NkRC")

    def click11(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=N0QxMEM2MDJDOUNGNEE5OEMyNTZFRTlGODlFRDNBMUUvQjc3MTBGRUYvN0E4MUFE")

    def click13(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=NEIwRTQxOURDRUIwRDY5MTUwNkZEM0Q0OTBBMEQ3OTgvQkJCMDNBMUIvQzZFNjQ3")

    def click15(c):
        wb.open(
            "http://www.csust.edu.cn/system/resource/storage/download.jsp?mark=NDc3QkJEREM2NzFEOTE5NkUzRTMzMThERjAxMUI3OEYvMDM5ODY5QjgvOEMzREY1")


    count = -1  # 为了换行定位使用
    name = entry1.get()
    # 文本框设置,在此地方放置有利于刷新
    text = Text(master, width=33, height=27)
    text.grid(row=1, column=1)
    # 判断输入大学是否在已搜集学校
    if name in texts.keys():
        for i in texts[str(name)]:
            text.insert(INSERT, i+"\n"+'\n')
            count+=2
            #定位并添加光标
            text.tag_add("{count}".format(count=count), "{count}.00".format(count=count), "{count}.14".format(count=count))
            text.tag_config("{count}".format(count=count), foreground='blue', underline=True)
            #添加鼠标点击响应,调用之前的函数
            text.tag_bind("{count}".format(count=count), '<Button-1>', eval("click{count}".format(count=count)), add=False)  # add=false 使得只添加一个响应,再次点击没有其他选项


# 鼠标右键定义
def copy(editor):
    editor.event_generate("<<Copy>>")
def paste(editor):
    editor.event_generate('<<Paste>>')
def rightKey(event, editor):
    menubar.delete(0, END)
    menubar.add_command(label = '复制', command = lambda: copy(editor))
    menubar.add_command(label = '粘贴', command = lambda: paste(editor))
    menubar.post(event.x_root, event.y_root)


# 显示框设置
master = Tk()  # 导入tkinter中的tk模块
menubar = Menu(master, tearoff = False)  # 创建一个菜单
master.title('考研试题下载')
master.geometry('530x560+900+60')

# 显示框样式
label1 = Label(master, text = '请输入学校名称:', font = ('GB2312', 16), fg = 'SteelBlue')
label1.grid(row = 0, column = 0)

label2 = Label(master, text = '搜索结果:', font = ('C71585', 16), fg = 'SteelBlue')
label2.grid(row = 1, column = 0)

# 输入框设置
entry1 = Entry(master, font = ('GB2312', 18), fg = 'Plum')
entry1.grid(row = 0, column = 1)
# 添加鼠标响应
entry1.bind("<Button-3>", lambda x: rightKey(x, entry1))

# 文本显示框
text = Text(master, width = 33, height = 27)
text.grid(row = 1, column = 1)

# 按钮设置
button1 = Button(master, text = '搜索', width = 10, font = ('GB2312', 18), background = 'Tan', command = main)
button1.grid(row = 2, column = 0, sticky = W)

button2 = Button(master, text = '退出', width = 10, font = ('GB2312', 18), background = 'Tan', command = master.quit)
button2.grid(row = 2, column = 1, sticky = E)

master.mainloop()

结果展示
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值