2016-05-17 197 views
0

我正在做一個需要創建一個python gui並使用c函數的項目。我已經嘗試安裝mysql-python,但它不起作用。我使用python3.4,xubuntu 16.04。請告訴我可能是什麼問題?錯誤:沒有名爲'mysql'的模塊

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() 
+0

你究竟試圖安裝它?我懷疑你已經安裝它爲python2 – arkhy

+0

我想我使用sudo pip安裝mysql-python –

回答

0

Python版本可能會引起混淆,特別是如果您使用apt進行安裝。 mysql-python是一個python 2包。 你可能想要安裝這一個

sudo apt-get install python3-mysql.connector 
+0

感謝它的工作! –

相關問題