import sqlite3
import tkinter as tk
import tkinter.ttk as ttk
class Table(tk.Frame):
def __init__(self, parent=None, headings=tuple(), rows=tuple()):
super().__init__(parent)
table = ttk.Treeview(self, show="headings", selectmode="browse")
table["columns"] = headings
table["displaycolumns"] = headings
for head in headings:
table.heading(head, text=head, anchor=tk.CENTER)
table.column(head, anchor=tk.CENTER)
for row in rows:
table.insert('', tk.END, values=tuple(row))
scrolltable = tk.Scrollbar(self, command=table.yview)
table.configure(yscrollcommand=scrolltable.set)
scrolltable.pack(side=tk.RIGHT, fill=tk.Y)
table.pack(expand=tk.YES, fill=tk.BOTH)
data = (,)
with sqlite3.connect('test.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM users")
data = (row for row in cursor.fetchall())
root = tk.Tk()
table = Table(root, headings=('Фамилия', 'Имя', 'Отчество'), rows=data)
table.pack(expand=tk.YES, fill=tk.BOTH)
root.mainloop()
В чем может быть проблема?
private void button1_Click(object sender, EventArgs e)
{
var fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance).Where(w => w.FieldType == typeof(CheckBox))
.Select(s => ((CheckBox)s.GetValue(this)).Name + "=" + ((CheckBox)s.GetValue(this)).Checked)
.ToList();
var fileContent = string.Join(",", fields);
File.AppendAllText("config.txt", fileContent);
}
private void Form1_Load(object sender, EventArgs e)
{
if(!File.Exists("config.txt")) return;
var fileContent = File.ReadAllText("config.txt");
var fieldsValues = fileContent.Split(',');
var fields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance).Where(w => w.FieldType == typeof(CheckBox)).ToList();
foreach(var field in fieldsValues)
{
var data = field.Split('=');
var name = data[0];
var value = bool.Parse(data[1]);
var fieldObj = fields.FirstOrDefault(f => f.Name == name);
if(fieldObj != null)
{
var checkBox = (CheckBox)fieldObj.GetValue(this);
checkBox.Checked = value;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
string[] names = { "first", "second", "threes" };
int yPosition = 33;
foreach (var name in names)
{
var checkBox = new CheckBox() { Location = new Point(101, yPosition), Text = name, };
checkBox.Click += (o, args) => { this.Select(name); };
this.Controls.Add(checkBox);
yPosition += 22;
}
}
public void Select(string name)
{
MessageBox.Show(name);
}