|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我是想做一个点选version会对应一个十六进制数字,然后转换为十进制。 比如选择 1----> 十六进制位置显示 0x1D4C00
写了个事件绑定,绑定左键点击的目标就会打印出来,但是显示出错了,
然后我把事件绑定的单独提取出来了,单独测试,结果却是可以用的。求大佬给个办法!
全局详情图:
全局详情
全局代码:from tkinter import * # 控件基础包,导入这个包后,这个包下的所有函数可以直接调用
from tkinter import filedialog, messagebox
from tkinter.ttk import Combobox
from urllib.parse import quote
class MainWindow():
# 初始化
def __init__(self):
top_button_width = 15 #用于设置按钮宽度
button_relief = RAISED #用于设置图标效果,这里设为凸起
# 创建顶层窗口
root = Tk()
self.src_filename = None
self.base_number_10 = StringVar()
self.base_number_10.set('00000000')
self.base_number_16 = StringVar()
self.base_number_16.set('00000000')
root.title('')
# 宽、高设为不可变,默认为True
root.resizable(width=False, height=False)
# 上部控件
b_open = Button(root, text='打开', relief=button_relief, width=top_button_width, bg='green')
b_open.grid(row=0, column=0, columnspan=2, sticky=W)
b_showall = Button(root, text='显示原文', relief=button_relief, width=top_button_width, bg='green')
b_showall.grid(row=0, column=2)
b_save = Button(root, text='保存', relief=button_relief, width=top_button_width, bg='green')
b_save.grid(row=0, column=3)
b_special = Button(root, text='特殊情况', relief=button_relief, width=top_button_width, bg='green')
b_special.grid(row=0, column=4)
# 空一行
la_blank = Label(root, text='')
la_blank.grid(row=1)
# 左侧控件
la_version = Label(root, text='VERSION')
la_version.grid(row=2, column=2, columnspan=2)
la_read = Label(root, text='请选择VERSION-->')
la_read.grid(row=3, column=0)
sb_version = Scrollbar(root) #添加滚动条
sb_version.grid(row=3, column=4, sticky=W+N+S) #使用grid时,这样才能填充满
li_version = Listbox(root, selectmode=SINGLE, yscrollcommand=sb_version.set, width=30)
li_version.bind('<ButtonRelease-1>', self.print_item)
for i in range(1000):
li_version.insert(END, str(i))
li_version.grid(row=3, column=2, columnspan=2)
sb_version.config(command=li_version.yview)
la_blank = Label(root, text='')
la_blank.grid(row=4)
la_10 = Label(root, text='十进制:===> ')
la_10.grid(row=5, column=0, sticky=E)
en_10 = Entry(root, textvariable=self.base_number_10,width=30)
en_10.grid(row=5, column=2, columnspan=2)
la_16 = Label(root, text='十六进制:===> ')
la_16.grid(row=6, column=0, sticky=E)
en_16 = Entry(root, textvariable=self.base_number_16, width=30)
en_16.grid(row=6, column=2, columnspan=2)
def print_item(event):
print(li_version.get(li_version.curselection()))
main = MainWindow()
mainloop()
提取详情图:
提取详情
提取代码:from tkinter import *
def print_item(event):
print(li_version.get(li_version.curselection()))
root = Tk()
sb_version = Scrollbar(root) #添加滚动条
sb_version.grid(row=3, column=2, sticky=W+N+S) #使用grid时,这样才能填充满
li_version = Listbox(root, selectmode=SINGLE, yscrollcommand=sb_version.set)
li_version.bind('<ButtonRelease-1>', print_item)
for i in range(1000):
li_version.insert(END, str(i))
li_version.grid(row=3, column=0, columnspan=2)
sb_version.config(command=li_version.yview)
from tkinter import * # 控件基础包,导入这个包后,这个包下的所有函数可以直接调用
from tkinter import filedialog, messagebox
from tkinter.ttk import Combobox
from urllib.parse import quote
def print_item(event):
print(li_version.get(li_version.curselection()))
top_button_width = 15 #用于设置按钮宽度
button_relief = RAISED #用于设置图标效果,这里设为凸起
# 创建顶层窗口
root = Tk()
src_filename = None
base_number_10 = StringVar()
base_number_10.set('00000000')
base_number_16 = StringVar()
base_number_16.set('00000000')
root.title('')
# 宽、高设为不可变,默认为True
root.resizable(width=False, height=False)
# 上部控件
b_open = Button(root, text='打开', relief=button_relief, width=top_button_width, bg='green')
b_open.grid(row=0, column=0, columnspan=2, sticky=W)
b_showall = Button(root, text='显示原文', relief=button_relief, width=top_button_width, bg='green')
b_showall.grid(row=0, column=2)
b_save = Button(root, text='保存', relief=button_relief, width=top_button_width, bg='green')
b_save.grid(row=0, column=3)
b_special = Button(root, text='特殊情况', relief=button_relief, width=top_button_width, bg='green')
b_special.grid(row=0, column=4)
# 空一行
la_blank = Label(root, text='')
la_blank.grid(row=1)
# 左侧控件
la_version = Label(root, text='VERSION')
la_version.grid(row=2, column=2, columnspan=2)
la_read = Label(root, text='请选择VERSION-->')
la_read.grid(row=3, column=0)
sb_version = Scrollbar(root) #添加滚动条
sb_version.grid(row=3, column=4, sticky=W+N+S) #使用grid时,这样才能填充满
li_version = Listbox(root, selectmode=SINGLE, yscrollcommand=sb_version.set, width=30)
li_version.bind('<ButtonRelease-1>', print_item)
for i in range(1000):
li_version.insert(END, str(i))
li_version.grid(row=3, column=2, columnspan=2)
sb_version.config(command=li_version.yview)
la_blank = Label(root, text='')
la_blank.grid(row=4)
la_10 = Label(root, text='十进制:===> ')
la_10.grid(row=5, column=0, sticky=E)
en_10 = Entry(root, textvariable=base_number_10,width=30)
en_10.grid(row=5, column=2, columnspan=2)
la_16 = Label(root, text='十六进制:===> ')
la_16.grid(row=6, column=0, sticky=E)
en_16 = Entry(root, textvariable=base_number_16, width=30)
en_16.grid(row=6, column=2, columnspan=2)
mainloop()
|
|