微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python tkinter Treeview 列比指定的多

如何解决Python tkinter Treeview 列比指定的多

我有以下 ttk Treeview 代码

listBox = ttk.Treeview(
    tab_player,columns=('Player','rating','Price'),selectmode="extended",)

listBox.heading('#0',text='Player',anchor=tk.CENTER)
listBox.heading('#1',text='rating',anchor=tk.CENTER)
listBox.heading('#2',text='Price',anchor=tk.CENTER)
listBox.column('#0',stretch=tk.YES,minwidth=50,width=80)
listBox.column('#1',width=20)
listBox.column('#2',width=30)

listBox.grid(row=5,column=5,rowspan=7,sticky=W)

我的插入函数如下:

def insertitem():
        GUI.listBox.insert('','end',values = (GUI.listBox_content.get(),GUI.listBoxr_content.get(),GUI.listBox_content_price.get()))

当我启动我的应用程序时,我有一个额外的列,插入的数据不是我想要的(数据在错误的列中)。

enter image description here

这是为什么?

解决方法

# include<iostream> # include<conio.h> # include<stdio.h> # include<stdlib.h> # include<windows.h> # include<cstdlib> # include<math.h> using namespace std; int main() { char Loai_math_problem; int Cau_tra_loi; int x,So_hang_thu_nhat,So_hang_con_lai,Tong; int So_tru,So_bi_tru,Hieu; int Thua_so_thu_nhat,Thua_so_thu_hai,Thua_so_con_lai,Tich; int So_chia,So_bi_chia,Thuong; system("cls"); printf("Short program made by C++ can solve X from a math problem with a sign (+,-,x,/).\nVer1.2."); Sleep(1200); printf("\nPress any key to continue!"); cau_tra_loi_chung://label chung getch(); system("cls"); printf("Okey! Let' start!\nType '+','-','x','/' to confirm."); Loai_math_problem=getch(); switch(Loai_math_problem) { case '+'://label + { buoc_tra_loi_phan_1: printf("\nOkey!\nWhat type of 'x'?\nType '1' in case like 1+4=x or '2' in case x+1=5 also 1+x=5\n"); scanf("%i",Cau_tra_loi); if(Cau_tra_loi==1) { printf("\nType the '1': "); scanf("%i",So_hang_thu_nhat); printf("\nType the '4': "); scanf("%i",So_hang_con_lai); printf(endl("X: %i",So_hang_thu_nhat + So_hang_con_lai)endl);//cout << endl << "X: " << So_hang_thu_nhat + So_hang_con_lai << endl; } if (Cau_tra_loi == 2) { printf("Type the '1': \n"); scanf("%i",So_hang_con_lai); printf("Type the '5': \n"); scanf("%i",Tong); printf("X: %i",Tong - So_hang_con_lai endl);//cout << "X: " << Tong - So_hang_con_lai << endl; } if(Cau_tra_loi<=0 ||Cau_tra_loi>=3) { printf("\nError: Invailid answer"); } break; } case '-': { buoc_tra_loi_phan_2://label - printf("\nOkey!\nWhat type of 'x'?\nType '1' in case like 4-1=x or '2' in case x-1=3 or '3' 4-x=3\n"); Cau_tra_loi=getch(); if (Cau_tra_loi == 1) { printf("\nType the '4': "); scanf("%i",So_bi_tru); printf("\nType the '1': "); scanf("%i",So_tru); printf(endl"X: %i",So_bi_tru - So_tru endl);//cout << endl << "X: " << So_bi_tru - So_tru << endl; } if (Cau_tra_loi == 2) { printf("Type the '1': \n"); scanf("%i",So_tru); printf("Type the '3': \n"); scanf("%i",Hieu); printf("X: %i",So_tru + Hieu endl);//cout << "X: " << So_tru + Hieu << endl; } if (Cau_tra_loi == 3) { printf("Type the '4': \n"); scanf("%i",So_bi_tru); printf("Type the '3': \n"); scanf("%i",So_bi_tru - Hieu endl);//cout << "X: " << So_bi_tru - Hieu << endl; } if(Cau_tra_loi<=0 || Cau_tra_loi>=4) { printf("\nError: Invailid answer"); } break; } case 'x': { buoc_tra_loi_phan_3://label x printf("\nOkey!\nWhat type of 'x'?\nType '1' in case like 1 x 5 = X or '2' in case X x 1 = 5 also 1 x X = 5\n"); Cau_tra_loi=getch(); if (Cau_tra_loi == 1) { printf("\nType the '1': "); scanf("%i",Thua_so_thu_nhat); printf("\nType the '5': "); scanf("%i",Thua_so_thu_hai); printf(endl"X: %ld",Thua_so_thu_nhat * Thua_so_thu_hai endl);//cout << endl << "X: " << Thua_so_thu_nhat * Thua_so_thu_hai << endl; } if (Cau_tra_loi == 2) { printf("Type the '1': \n"); scanf("%i",Thua_so_con_lai); printf("Type the '5': \n"); scanf("%i",Tich); printf("X: %lf",Tich/Thua_so_con_lai endl);//cout << "X: " << Tich/Thua_so_con_lai << endl; } if(Cau_tra_loi<=0 || Cau_tra_loi>=3) { printf("\nError: Invailid answer"); } break; } case '/': { buoc_tra_loi_phan_4://label / printf("\nOkey!\nWhat type of 'x'?\nType '1' in case like 4/1=x or '2' in case x/1=4 or '3' 4/x=1\n"); Cau_tra_loi=getch(); if (Cau_tra_loi == 1) { printf("\nType the '4': "); scanf("%i",So_bi_chia); printf("\nType the '1': "); scanf("%i",So_chia); printf(endl"X: %lf",So_bi_chia/So_chia endl);//cout << endl << "X: " << So_bi_chia/So_chia << endl; } if (Cau_tra_loi == 2) { printf("Type the '1': \n"); scanf("%i",So_chia); printf("Type the '4': \n"); scanf("%i",Thuong); printf("X: %ld",So_chia * Thuong);//cout << "X: " << So_chia * Thuong << endl; } if (Cau_tra_loi == 3) { printf("Type the '4': \n"); scanf("%i",So_bi_chia); printf("Type the '1': \n"); scanf("%i",Thuong); printf("X: %%lf",So_bi_chia/Thuong);//cout << "X: " << So_bi_chia/Thuong << endl; } if(Cau_tra_loi<=0 || Cau_tra_loi>=4) { printf("\nError: Invailid answer"); } break; } default: { printf("Error: Invailid answer. To conttinue,press any key!"); break; } } getch(); printf("\nPress any key to end the program!"); exit(0); } 总是指树列,而不是数据列。因此,请改用 "#0" 并设置 "#1","#2","#3" 以隐藏 树列

show="headings"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。