0

I'm doing a project that requires to create a python gui and use c functions. I have tried installing mysql-python but It doesn't work. I'm using python3.4, xubuntu 16.04. Please tell me what can be the problem?

from ctypes import *
# Simple enough, just import everything from tkinter.
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import subprocess
# Here, we are creating our class, Window, and inheriting from the Frame
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
import mysql.connector

cnx = mysql.connector.connect(user='root', password='root',
                          host='127.0.0.1',
                          database='iCalender')
cnx.close()

cal = CDLL('./caltool.so')
class Window(Frame):

# Define settings upon initialization. Here you can specify
def __init__(self, master=None):

    # parameters that you want to send through the Frame class.
    Frame.__init__(self, master)
    fm = Frame(root, width=400, height=300, bg="green")
    fm.pack(side=TOP, expand=NO, fill=NONE)
    #reference to the master widget, which is the tk window
    self.master = master

    #with that, we want to then run init_window, which doesn't yet exist
    self.init_window()

#Creation of init_window
def init_window(self):

    # changing the title of our master widget
    self.master.title("XCal Application")

    # allowing the widget to take the full space of the root window
    self.pack(fill=BOTH, expand=1)

    # creating a menu instance
    menu = Menu(self.master)
    self.master.config(menu=menu)

    # create the file object)
    file = Menu(menu)

    # adds a command to the menu option, calling it exit, and the
    # command it runs on event is client_exit
    file.add_command(label="Open", command=self.OpenFile, accelerator="Ctrl+O")
    file.add_command(label="Save", command=self.file_save, accelerator="Ctrl+S")
    file.add_command(label="Save As...", command=self.client_exit, accelerator="Ctrl+Shift+S")
    file.add_command(label="Combine", command=self.client_exit)
    file.add_command(label="Filter", command=self.client_exit)
    file.add_command(label="Exit", command=self.client_exit, accelerator="Ctrl+X")
    self.bind_all("<Control-x>", self.client_exit)
    self.bind_all("<Control-o>", self.OpenFile)
    self.bind_all("<Control-s>", self.file_save)

    #added "file" to our menu
    menu.add_cascade(label="File", menu=file)

    # create the file object)
    edit = Menu(menu)

    # adds a command to the menu option, calling it exit, and the
    # command it runs on event is client_exit
    edit.add_command(label="To Do List", accelerator="Ctrl+T")
    edit.add_command(label="Undo", accelerator="Ctrl+Z")

    #added "file" to our menu
    menu.add_cascade(label="Todo", menu=edit)
    help1 = Menu(menu)
    help1.add_command(label="Date Mask")
    help1.add_command(label="About xcal")
    menu.add_cascade(label="Help", menu=help1)


def client_exit(self, event):
    exit()
def OpenFile(self):
    filename = askopenfilename()
    print(filename)
    cal.pyGetInfo(filename)
def file_save(self, event):
    name = asksaveasfile(mode='w',defaultextension=".txt")
    text2save=str(text.get(0.0,END))
    name.write(text2save)
    name.close


# root window created. Here, that would be the only window, but
# you can later have windows within windows.
root = Tk()

root.geometry("400x300")

#creation of an instance
app = Window(root)

#mainloop
root.mainloop()
2
  • how exactly have you tried to install it? I suspect that you have installed it for python2
    – arkhy
    May 17, 2016 at 20:33
  • I think I used sudo pip install mysql-python May 17, 2016 at 20:39

1 Answer 1

0

Python versions can be confusing, especially if you install with apt. mysql-python is a python 2 package. You probably want to install this one

sudo apt-get install python3-mysql.connector
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.